Installing your own Python Modules

From SciNet Users Documentation
Revision as of 00:05, 29 May 2018 by Mponce (talk | contribs) (Created page with "=Python Virtual Environments= == Using Python Virtualenv == Virtual environments (short virtualenv) are a standard in Python to create isolated Python environments. This is...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Python Virtual Environments

Using Python Virtualenv

Virtual environments (short virtualenv) are a standard in Python to create isolated Python environments. This is useful when certain modules or certain versions of modules are not available in the thee default python environment. First load a python module:

module load intel/13.1.1 python/2.7.5

Then install virtualenv:

pip install virtualenv --user

Then create a directory for the virtual environments. One can put an virtual environment anywhere, but this directory structure is recommended:

mkdir ~/.virtualenvs
cd ~/.virtualenvs

Now we create our first virtualenv called myenv choose any name you like:

~/.local/bin/virtualenv myenv

After that we can activate that virtual environment:

source ~/.virtualenvs/myenv/bin/activate

To go back to the normal python installation simply type "deactivate" As you are in the virtualenv now you can just type pip install <required module> to install any module in your virtual environment

Installing the scientific python suite

For many scientific codes the packages numpy, scipy, matplotlib, pandas and ipython are used. Except scipy all of these install very simply in a virtualenv using the pip install <package name>.

For installing scipy we first need to install numpy and then copy scinet's site.cfg (contains paths to the required libraries for scipy). So before doing "pip install scipy" do

cp /scinet/gpc/tools/Python/Python275-shared-intel/lib/python2.7/site-packages/numpy/distutils/site.cfg ~/.virtualenvs/myenv/lib/python2.7/site-packages/numpy/distutils/

and then just do pip install scipy