Installing your own Python Modules: Difference between revisions

From SciNet Users Documentation
Jump to navigation Jump to search
Mponce (talk | contribs)
No edit summary
 
(38 intermediate revisions by 6 users not shown)
Line 1: Line 1:
=Python Virtual Environments=
Python virtual environments are documented on the Alliance wiki:
https://docs.alliancecan.ca/wiki/Python#Creating_and_using_a_virtual_environment


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.
That page covers the current modules and job examples for Trillium. For
 
SciNet-specific access, see [[Trillium Quickstart]].
VirtualEnv can be used either with the default python modules or the anaconda ones.
 
== Using Python VirtualEnv in Anaconda ==
 
VirtualEnv are right built-in in Anaconda, see [https://conda.io/docs/user-guide/tasks/manage-environments.html]
You just need to load the proper anaconda module, eg.
 
<source lang="bash">
 # load the anaconda module
 module load python/3.6.4-anaconda5.1.0
 
 # create a virtual env.
 conda create -n myPythonEnv python=3.6
 
 # activate your vitual env.
 source activate myPythonEnv
 
 # at this point you are in your own environment and can just do the installation of any package that you need, eg.
 pip install myFAVpackage
 
</source>
 
== Using Python Virtualenv in plain Python ==
 
First load a python module:
 
<source lang="bash">
module load python/2.7.14
</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">
virtualenv myEnv
</source>
 
After that you 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.
All of these install very simply in a virtualenv using the ''pip install <package name>''.

Latest revision as of 17:44, 9 November 2026

Python virtual environments are documented on the Alliance wiki: https://docs.alliancecan.ca/wiki/Python#Creating_and_using_a_virtual_environment

That page covers the current modules and job examples for Trillium. For SciNet-specific access, see Trillium Quickstart.