Python // Lesson 7: Libraries, PIP, and Virtual Environments

  1. Importing Libraries
    Video link
    Length is 5 minutes
  2. sys.path and PYTHONPATH
    Video link
    Length is 7 minutes
  3. pip
    Video link
    Length is 7 minutes
  4. Virtual Environments
    Video link
    Length is 6 minutes
  5. Creating a Simple Python Module
    Video link
    Length is 4 minutes

Additional Content:

A non-magical introduction to Pip and Virtualenv for Python beginners​

Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages​
Read the “Using pip” section.


Reference code for these exercises is posted on GitHub at:

1a. Import the ‘datetime’ library. Print out the module that is being imported by datetime (the __file__ attribute)

Import the Python ipaddress library. Print out the module that is being imported by ipaddress (the __file__ attribute). If you are using Python 2.7, you will need to pip install the ipaddress library.

Import sys and use pprint to pprint sys.path

1b. In a separate Python file named ‘’, define a dictionary named ‘rtr1’ with the following key-value pairs:

host =
username = cisco
password = cisco123
device_type = cisco_ios

Import my_devices into this program, and print the rtr1 dictionary to the screen using pprint.

1c. In a Python shell, try importing the ‘my_devices’ when is not in your current working directory.

What exception do you get when you do this?

Update your PYTHONPATH environment variable so that you are successfully able to import this module.

2a. Create a new virtual environment on your system named ‘test_venv’.

b. Activate the virtual environment

c. Use ‘which python’ to see the path of the Python that you are using.

d. Use ‘pip list’ to see the packages you have installed.

e. Use pip to install Netmiko and the requests library.

f. Use ‘pip list’ to see the updated list of installed packages.

3a. Using the same ‘test_venv’ that you created in exercise2, install netmiko version 2.0.1. Verify that this version is installed by executing the following from the Python shell:

>>> import netmiko
>>> netmiko.__version__

b. Using pip, upgrade your version of Netmiko to the latest version.

c. Deactivate your virtual environment. See ‘which python’ is now being used.

4a. Activate your ‘test_venv’ virtual environment.

b. Use pip to uninstall the Netmiko library.

c. Verify that Netmiko is no longer installed.

d. Use pip to install the ‘develop’ branch of Netmiko.