How to create a python environment

`Simple Python Version Management with pyenv, see https://github.com/yyuu/pyenv

Python package management with pip (python version 2) or pip3 (python version 3)

examples:

$ pip3 install --target $MyPipRepo -r $MyRequirements.txt
$ pip3 install --target /export01/mriqc -r https://github.com/poldracklab/mriqc/blob/master/docs/requirements.txt

Creating Virtual Environments, see https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments

… with Anaconda - https://www.anaconda.com/products/individual

Anaconda is better at handling non-python dependencies and it is also well supported. You can download the installer script for your platform and follow instructions. Make sure to
save this installer script in a directory with enough storage as your BIC account storage is limited by a fixed quota. Watch the tutorial and refer to the Quick Start Guide.

Here’s an installation example: set $PREFIX to the location where you want it installed, somewhere with gigabytes available, 10GB or more! Then follow instrutions.

$ bash /tmp/Anaconda3-2020.11-Linux-x86_64.sh -p $PREFIX

$ bash /tmp/Anaconda3-2020.11-Linux-x86_64.sh -p /export01/conda

if you decide to answer yes towards the end to allow the script to initialize Anaconda3, then you should deactivate (as suggested) conda upon (shell) startup, otherwise it may break other workflows that you use, those that depend on other python versions like an old version of FSL for example. Say no to the initialization phase to avoid this.

to startup anaconda,…

$ source /export01/conda/etc/profile.d/conda.sh
$ conda -h

there are many possibilities at this stage, but perhaps the next step would be to create an environment, for example:

$ source /export01/conda/etc/profile.d/conda.sh
$ conda create -n py3env python=3.8
$ conda activate py3env
(py3env) me@work:~$ python --version
Python 3.8.5
(py3env) me@work:~$ conda install spyder
(py3env) me@work:~$ spyder
(py3env) me@work:~$ conda deactivate

other resources: https://docs.anaconda.com/anaconda/, https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html

1 Like