Difference between revisions of "User Python virtualenv"

From oldwiki.scinet.utoronto.ca
Jump to navigation Jump to search
m
 
Line 1: Line 1:
 +
{| style="border-spacing: 8px; width:100%"
 +
| valign="top" style="cellpadding:1em; padding:1em; border:2px solid; background-color:#f6f674; border-radius:5px"|
 +
'''WARNING: SciNet is in the process of replacing this wiki with a new documentation site. For current information, please go to [https://docs.scinet.utoronto.ca https://docs.scinet.utoronto.ca]'''
 +
|}
  
 
== Using Python Virtualenv ==
 
== Using Python Virtualenv ==

Latest revision as of 19:32, 31 August 2018

WARNING: SciNet is in the process of replacing this wiki with a new documentation site. For current information, please go to https://docs.scinet.utoronto.ca

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:

<source lang="bash"> module load intel/13.1.1 python/2.7.5 </source>

Then install virtualenv:

<source lang="bash"> pip install virtualenv --user </source>

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

<source lang="bash"> mkdir ~/.virtualenvs cd ~/.virtualenvs </source>

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

<source lang="bash"> ~/.local/bin/virtualenv myenv </source>

After that we can activate that virtual environment:

<source lang="bash"> source ~/.virtualenvs/myenv/bin/activate </source>

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

<source lang="bash"> 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/ </source>

and then just do pip install scipy