Python Packages

We are nearly ready to start interacting with AWS. Before we do this we need to install some additional software called a package.

A python package is code comprising of individual components called modules that we can use in our code. Packages save us from having to write every aspect of our program from scratch by allowing us to use other peoples code. By importing packages into our program we can use the features of that package. Python has common packages that are included, others have to be installed into our virtual environment using the python package manager pip.

To work with AWS you will need to install the Boto3 package. Do that now.

At the command prompt in the terminal type:

pip install boto3

The command should run and install a number of packages. You might also get a message similar to the one below.

You are using pip version 18.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

You can go ahead and install the latest version of pip by typing in the command.

If you get an error message. Check you have exited from the python interactive environment indicated by >>>. You should be at $ prompt in the shell.

You can see what packages you have installed at any time by typing the following:

pip freeze

which will return something similar to:


Creating a requirements.txt file

When you use pip freeze you see all the packages installed into your virtual environment. We need to be able to recreate the set of packages when the code is reused elsewhere. For example, giving the code to someone else or when running it in a different environment. To accomplish this pip uses a requirements.txt file. This file contains a list of all the packages and versions you need to install the new environment.

You can create a requirements.txt file by using the command pip freeze > requirements.txt

This will create the requirements.txt file in the current directory.

To install a requirements.txt file in the new virtual environment you type pip install -r requirements.txt in the new virtual environment to install all the same packages and dependencies from that file.