How-to: Python packages

Action

This document will give you a quick overview of installing custom packages into python. There are two primary ways to do so, one is with pip install --user and the other is virtualenv; both have advantages and disadvantages.

Instructions

Using virtualenv

Here are the examples using virtualenv, the benefit here is that in a shared space many users could collaborate on one custom instances of packages for their group if the venv is created inside a lab share.

Python 2.7

Here we see that numpy is not installed.

ew2193@headnode7.rit.albany.edu:~/python_project 2.08 1.66 1.00 3/201 5951 1031 > /network/rit/misc/software/python2/bin/python2.7 Python 2.7.12 (default, Aug 10 2016, 15:38:28) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named numpy >>>

 

Here we will use virtualenv to setup a virtual python installation and activate it.

ew2193@headnode7.rit.albany.edu:~/python_project 2.08 1.66 1.00 3/201 5951 1032 > virtualenv venv New python executable in /network/rit/home/ew2193/python_project/venv/bin/python Installing setuptools, pip, wheel...done. ew2193@headnode7.rit.albany.edu:~/python_project 2.08 1.66 1.00 3/201 5951 1033 > source venv/bin/activate (venv)

 

 

Once activated we can use the standard tools like pip to install additional standard libraries.

ew2193@headnode7.rit.albany.edu:~/python_project 2.08 1.66 1.00 3/201 5951 1034 > pip install numpy Collecting numpy Downloading numpy-1.11.1-cp27-cp27m-manylinux1_x86_64.whl (15.3MB) 100% |████████████████████████████████| 15.3MB 59kB/s Installing collected packages: numpy Successfully installed numpy-1.11.1 (venv) ew2193@headnode7.rit.albany.edu:~/python_project 2.08 1.66 1.00 3/201 5951 1035 > python Python 2.7.12 (default, Aug 10 2016, 15:38:28) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> help(numpy) Help on package numpy: NAME numpy FILE /network/rit/home/ew2193/python_project/venv/lib/python2.7/site-packages/numpy/__init__.py DESCRIPTION NumPy =====

 

If we deactivate we are back to the system level python and stock packages.

 

Python 3

Here is the same set of commands using python3 rather than python2. You will notice only slight changes from the python2 version.

Â