3.1.12 Lab - Explore Python Development Tools
3.1.12 Lab - Explore Python Development Tools
Objectives
Part 1: Launch the DEVASC VM
Part 2: Review the Python Installation
Part 3: PIP and Python Virtual Environments
Part 4: Sharing Your Virtual Environment
Background / Scenario
This course has some basic expectations for students, that they have some background in Python and some
hands-on experience with programming. Lab practice with Python gives your fingers the "muscle memory" to
work more efficiently in Python. However, initially it is important for you to know how to maintain a Python
development environment.
In this lab, you review Python installation, PIP, and Python virtual environments.
Required Resources
• 1 PC with operating system of your choice
• Virtual Box or VMWare
• DEVASC Virtual Machine
Instructions
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 8 www.netacad.com
Lab - Explore Python Development Tools
b. To see the directory for the local Python environment, use the which python3 command.
devasc@labvm:~$ which python3
/usr/bin/python3
devasc@labvm:~$
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 8 www.netacad.com
Lab - Explore Python Development Tools
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 8 www.netacad.com
Lab - Explore Python Development Tools
d. Re-enter the pip3 freeze command to see the packages now installed in the devfun environment.
Note: Your list of packages and version numbers may be slightly different.
(devfun) devasc@labvm:~/labs/devnet-src/python$ pip3 freeze
certifi==2020.4.5.1
chardet==3.0.4
idna==2.10
requests==2.24.0
urllib3==1.25.9
(devfun) devasc@labvm:~/labs/devnet-src/python$
e. To deactivate the virtual environment and go back to your system, enter the deactivate command.
(devfun) devasc@labvm:~/labs/devnet-src/python$ deactivate
devasc@labvm:~/labs/devnet-src/python$
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 8 www.netacad.com
Lab - Explore Python Development Tools
b. If you want to quickly find the version of a package installed, pipe the output to the grep command. Enter
the following to see the version of the requests package currently installed.
devasc@labvm:~/labs/devnet-src/python$ python3 -m pip freeze | grep requests
requests==2.22.0
requests-kerberos==0.12.0
requests-ntlm==1.1.0
requests-toolbelt==0.9.1
requests-unixsocket==0.2.0
devasc@labvm:~/labs/devnet-src/python$
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 8 www.netacad.com
Lab - Explore Python Development Tools
b. Send the output of the pip3 freeze command to a text file called requirements.txt.
(devfun) devasc@labvm:~/labs/devnet-src/python$ pip3 freeze >
requirements.txt
c. Deactivate the devfun virtual environment. You can use the ls command to see that the
requirements.txt file is in the /python directory.
(devfun) devasc@labvm:~/labs/devnet-src/python$ deactivate
devasc@labvm:~/labs/devnet-src/python$ ls
devfun file-access-input.py if-acl.py requirements.txt
devices.txt file-access.py if-vlan.py while-loop.py
devnew hello-world.py person-info.py
e. Use the pip3 install -r requirements.txt command to install the same packages that are installed in the
devfun virtual environment.
(devnew) devasc@labvm:~/labs/devnet-src/python$ pip3 install -r
requirements.txt
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 8 www.netacad.com
Lab - Explore Python Development Tools
Collecting certifi==2020.4.5.1
Using cached certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
Collecting chardet==3.0.4
Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting idna==2.9
Using cached idna-2.9-py2.py3-none-any.whl (58 kB)
Requirement already satisfied: pkg-resources==0.0.0 in ./devnew/lib/python3.8/site-
packages (from -r requirements.txt (line 4)) (0.0.0)
Collecting requests==2.23.0
Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB)
Collecting urllib3==1.25.9
Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
Installing collected packages: certifi, chardet, idna, urllib3, requests
Successfully installed certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 requests-2.23.0
urllib3-1.25.9
(devnew) devasc@labvm:~/labs/devnet-src/python$
f. When entering pip3 freeze in the devnew environment, you should see the following output.
(devnew) devasc@labvm:~/labs/devnet-src/python$ pip3 freeze
certifi==2020.4.5.1
chardet==3.0.4
idna==2.9
pkg-resources==0.0.0
requests==2.23.0
urllib3==1.25.9
(devnew) devasc@labvm:~/labs/devnet-src/python$
g. Deactivate the devnew virtual environment.
(devnew) devasc@labvm:~/labs/devnet-src/python$ deactivate
devasc@labvm:~/labs/devnet-src/python$
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 8 www.netacad.com
Lab - Explore Python Development Tools
End of document
© 2020 - 2024 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 8 www.netacad.com