ud036 ยป

Manually Installing a Python Package

In this course, you will use packages outside the Python standard library, such as twilio.  Most external libraries are available through tools such as pip and easy_install.  If you install these, installing packages is usually as easy as writing

pip install twilio

in your terminal or command prompt.  However, you can always install a package manually if it is unavailable through these tools or you cannot get them working.  First, download the source code of the package.  This should be available from the developer's website, and typically comes in the form of a zip folder.  Unzip the folder, and take a look inside.  There is often a README or installation instructions.  If they are present, follow them.  If not, there is a standard way that packages are installed.  To start, open your terminal or command prompt.  You are going to change the working directory of your command line to the folder you just unzipped.  To do this on Mac or Linux, enter this command:

cd path_to_folder/package_folder_name

replacing path_to_folder and package_folder_name with the path to that folder from your home directory and the folder's name.  For example, if you download easygui-0.9.4.zip (the latest version of the easygui package) and unzip the folder in your Downloads folder, you would enter

cd Downloads/easygui-0.9.4

On Windows, type the same command except replace all / characters with \.  Yeah, I know.  Why can't we all agree on one slash direction?

The cd command stands for change directory, and it changes the focus of your command prompt to the specified directory.  Now we can run commands that affect the files in this folder.  To install the package, enter:

python setup.py install

And that's it! The package will install.  Note that on some operating systems you will require administrative privileges to run this command, so you would enter sudo python setup.py install instead.  This works for most packages, and any others will contain their own instructions for installation.  This may fail if the package you downloaded is not compatible with your version of Python.  Many developers offer separate versions of their packages that work with Python 2 and 3.  Make sure to get the one that's right for you!

For more detailed information on this process, see the Python website.  (Note that you can change which version of Python you want documentation for through the drop down menu at the top.)