Practice Cisko 4
Practice Cisko 4
Equipo 10
Godoy Jiménez Joaquín - 19030394
Montenegro Zúñiga Marco Antonio - 19030546
Yañez Oñate Juan Pablo - 19030179
Parcial 2
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 10 www.netacad.com
Lab - Explore Python Development Tools
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
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 10 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:~$
b.Enter the following command to use the venv tool to create a Python 3 virtual environment with the name
devfun. The -m switch tells Python to run the venv module. The name is chosen by the programmer.
devasc@labvm:~/labs/devnet-src/python$ python3 -m venv devfun
devasc@labvm:~/labs/devnet-src/python$
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 10 www.netacad.com
Lab - Explore Python Development Tools
b. Run the pip3 freeze command to verify that there are no additional Python packages currently installed in
the devfun environment.
(devfun) devasc@labvm:~/labs/devnet-src/python$ pip3 freeze
(devfun) devasc@labvm:~/labs/devnet-src/python$
c. Now install the Python requests package within the devfun environment.
(devfun) devasc@labvm:~/labs/devnet-src/python$ pip3 install requests
Collecting requests
Downloading requests-2.23.0-py2.py3-none-any.whl (58 kB)
|████████████████████████████████| 58 kB 290 kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Downloading urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
|████████████████████████████████| 126 kB 1.7 MB/s
Collecting idna<3,>=2.5
Downloading idna-2.9-py2.py3-none-any.whl (58 kB)
|████████████████████████████████| 58 kB 18.3 MB/s
Collecting certifi>=2017.4.17
Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
|████████████████████████████████| 157 kB 19.8 MB/s Collecting
chardet<4,>=3.0.2
Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 59.2 MB/s
Installing collected packages: urllib3, idna, certifi, chardet, requests
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 10 www.netacad.com
Lab - Explore Python Development Tools
Successfully installed certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 requests-2.23.0
urllib3-1.25.9
(devfun) devasc@labvm:~/labs/devnet-src/python$
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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 10 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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 10 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
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)
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 10 www.netacad.com
Lab - Explore Python Development Tools
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/sitepackages (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$
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 10 www.netacad.com
Lab - Explore Python Development Tools
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 10 www.netacad.com
Lab - Explore Python Development Tools
Conclusiones
Es una buena práctica para ir entendiendo mejor Python, por mi parte no tengo
mucha aproximación con este lenguaje, hasta este semestre lo aprenderé, y
considero que es un buen camino para practicar y mejorar, hay que aprovechar
también el entorno virtual y las herramientas que están a nuestro alcance.
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 10 www.netacad.com