For Python 2, we recommend using the python/2.7.16 module. For Python 3, we recommend using the python/3.7.4 module.
There are several ways for users to install python packages on Oscar
using a virtual environment
into their home directory
into a custom location
from source into a custom location
Virtual environments are a cleaner way to install python packages for a specific workflow. This webpage gives a good explanation of the use cases. In the example below, a virtual environment called 'my_cool_science' is set up in your home directory:
module load python/2.7.16cd ~virtualenv my_cool_sciencesource ~/my_cool_science/bin/activatepip install <your package>deactivate
line 1: load the version of python you want to use
line 2: change directory to home
line 3: create the virtual environment
line 4: activate the virtual environment
line 5: install any packages you need for the virtual environment
line 6: deactivate the environment
When you want to use the environment, e.g. in a batch script or an interactive session
When your work is finished, deactivate the environment with
--user flag will instruct pip to install to you home directory
pip install --user <package>
This will install the package under the following path in user's HOME directory:
Python packages can often have conflicting dependencies. For workflows that require a lot of python packages, we recommend using virtual environments.
Users have a limit of 20GB for their home directories on Oscar. Hence, users might want to use their data directory instead for installing software. Another motivation to do that is to have shared access to the software among the whole research group.
pip install --target=</path/to/install/location> <package>
This path to install location will have to be added to the PYTHONPATH environment variable so that python can find the python modules to be used. This is not necessary for software installed using the
This can be added at the end of your
.bashrc file in your home directory. This will update the PYTHONPATH environment variable each time during startup. Alternatively, you can update PYTHONPATH in your batch script as required. This can be cleaner as compared to the former method. If you have a lot of python installs at different locations, adding everything to PYTHONPATH can create conflicts and other issues.
A caveat of using this method is that pip will install the packages (along with its requirements) even if the package required is already installed under the global install or the default local install location. Hence, this is more of a brute force method and not the most efficient one.
For example, if your package depends on numpy or scipy, you might want to use the numpy and scipy under our global install as those have been compiled with MKL support. Using the
--target option will reinstall numpy with default optimizations and without MKL support at the specified location.
Sometimes, python software is not packaged by the developers to be installed by pip. Or, you may want to use the development version which has not been packaged. In this case, the python package can be installed by downloading the source code itself. Most python packages can be installed by running the
setup.py script that should be included in the downloaded files.
This will create the sub-directories
lib, etc. at the location provided above and install the packages there. The environment will have to be set up accordingly to use the package:
export PATH=</path/to/install/location>/bin:$PATHexport PYTHONPATH=</path/to/install/location>/lib/python<version>/site-packages:$PYTHONPATH