Python

Requirements:

  • Environment Modules

The guide assumes basic understanding of the above requirements

Python is a general-purpose, versatile and popular programming language. It’s great as a first language because it is concise and easy to read, and it is also a good language to have in any programmer’s stack as it can be used for everything from web development to software development and scientific applications.

 

Versions

The following versions are available on EECS Servers and Desktops:

Version Available as
Binaries PATH
2.7 Default system version /bin/python
3.4 RPM package, Environment module /bin/python3.4
3.6.9 Environment module /import/linux/python/3.6.9/bin/python
3.6.10 Environment module /import/linux/python/3.6.10/bin/python
3.7.7 Environment module /import/linux/python/3.7.7/bin/python
3.8.2 Environment module /import/linux/python/3.8.2/bin/python

Using Python

The versions in the table above are available as environment modules, that enables users to load and switch between different Python versions with just one command.

For example, if you need to use the provided Python 3.6.10 , from the command line:

$ module load python/3.6.10

To check the version of the Python you are now using:

$ python -V
Python 3.6.10

Installing Python packages

Users do not have “admin” priviliges to install Python packages on the EECS systems, but any Python packages can be installed inside a user’s home directory with more than one ways. We recommend using virtualenv for more efficient workflow.

Choose any tab to how you can install Python packages in your home directory:

 

Virtualenv give the ability to create isolated Python Virtual Environments with specific packages and different versions for every project you are working on. Python Virtualenv helps keeping  the unique dependencies for every project separate, locally and in an isolated folder with the same name of the virtualenv.

To work with a specific  virtualenv, you must “activate” and when you’ve finished you have to “deactivate” it.

Load the module

First, load the Python versions of your choice from the available environment modules . For example, to use Python 3.6.10:

  $ module load python/3.6.10

Check that you loaded the right Python version:

$ python -V 
Python 3.6.10

Create the virtualenv

To create a virtualenv:

$ python -m venv <venv_name>

That will create a folder with the name you provided above which contains your new Python virtualenv.

$ ls <venv_name>/
bin include lib lib64 pyvenv.cfg

Activate the virtualenv

To activate and start using the new virtualenv:

$ source <venv_name>/bin/activate
(<venv_name>) $

You will notice that your prompt has changed and the name of the activated virtualenv has been added at the beginning of each line. That shows that you have successfully activated the virtualenv and its name.

Now you can start installing your own packages.

Install a package

To install a Python package, simply run:

(<venv_name>) $ pip install <package_name>

To install a specific version of a package you must define it like:

(<venv_name>) $ pip install <package_name>==<version>

Deactivate virtualenv

To stop using the current virtualenv:

(<venv_name>) $ deactivate
$

Anaconda is an open-source distribution of Python and R for scientific computing. It provides an easy way to manage the Python packages you install and the virtualenv you create.

For more info on how to install Python packages using Anaconda, read our Anaconda Guide.

Python packages can be installed to your $HOME directory by adding the --user option. This requires to manually update your local SHELL to point at the location of the installed binaries and libraries.

Load the module

First, load the Python versions of your choice from the available environment modules . For example, to use Python 3.6.10:

  $ module load python/3.6.10

Install a package

To install a Python package,  run:

$ pip install --user <package_name>

It will install the contents of the package at:

• Binaries: $HOME/.local/bin

• Modules/Libraries: $HOME/.local/lib/pythonX.Y/site-packages

Update local environment

Depending on your local environment variables, you might need to add at least the following (replace X.Y with the Python version you used to install the packages):

$ export PATH=~/.local/bin:$PATH
$ export PYTHONPATH=​$HOME/.local/lib/pythonX.Y/site-packages:$PYTHONPATH

References

 

Tensorflow

Requirements

Make sure you have enough available disk space in your home directory: Disk quotas

This guide assumes you are already familiar with:

Info

TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications. For information and usage, please read the official documentation: Learn Tensorflow

TensorFlow 1.x uses separate packages for CPU and GPU support, tensorflow (non-GPU dependent) and tensorflow-gpu(requires CUDA/cuDNN).

TensorFlow 2.x is released with both CPU and GPU support.

Install tensorflow

This example uses Anaconda to install tensorflow-gpu==1.15 inside a Python 3.6.10 virtual environment with the name dev_tensorflow_1, using CUDA-10.0 with cuDNN-7.5.9

Click on any tab to find how to install tensorflow using different methods.

Loading the module

Load any of the available Python versions we provide, in the form of environment modules . For example, to use the available Python 3.6.10:

  $ module load python/3.6.10

Check the Python version:

$ python -V 
Python 3.6.10

Loading CUDA

Load the combination of CUDA/cuDNN that is suitable for you. For example:

 $ module load cuda/10.0-cudnn7.5.0

Create the environment

Create a new Python Virtual environment (venv) and define a name, for example to create a venv with the name dev_tensorflow_1:

$ python -m venv dev_tensorflow_1

Activate the environment:

 $ source dev_tensorflow_1/bin/activate
(dev_tensorflow_1) $

Install packages

Install the tensorflow version you need:

(dev_tensorflow_1) $ pip install tensorflow-gpu==1.15

To check the version of tensorflow you just installed:

(dev_tensorflow_1) $ python
>>> import tensorflow as tf
>>> print(tf.VERSION)
1.15.0

 

Loading the module

To load the default installed version of Anaconda (Python3), load the anaconda3 module:

$ module load anaconda3

Check the Python version:

$ python -V 
Python 3.7.4

Loading CUDA

Load the combination of CUDA/cuDNN that is suitable for you. For example:

 $ module load cuda/10.0-cudnn7.5.0

Create the environment

Create a new Anaconda environment and define a name, for example to create an environment with the name dev_tensorflow_1:

$ conda create --yes --quiet --name dev_tensorflow_1

Activate the environment:

$ source activate dev_tensorflow_1
(dev_tensorflow_1) $

Install packages

Install the tensorflow version you need:

(dev_tensorflow_1) $ conda install tensorflow==1.15

Check the installed packages:

(dev_tensorflow_1) $ conda list

Check the installed tensorflow version

(dev_tensorflow_1) $ python -c "import tensorflow as tf; print(tf.VERSION)"
1.15.0

 

 

References