Anaconda (including conda) is installed on Linux desktop machines as an optional module. Use this instead of using pip with the distribution-supplied python within our desktop Ubuntu. There is a conda tutorial and a 'cheat sheet'.
As a simple test, use the following series of commands.
# Please note that the versions of anaconda we # make available changes over time. # To see which versions are available, run: module av anconda # You probably want to use the latest version we provide unless you # have a definite reason to choose another. At the time of writing, # the latest version we provide is anaconda/python3/2022.05 so: module load anaconda/python3/2022.05 conda create -n test scipy
This installs the most recent versions of numpy and scipy into the conda environment test created above, which by default will be in your home directory. These are usually newer package versions than those that come with Ubuntu.
Follow the steps given in the pages on managing environments to activate the new conda environment test. The command would be as follows.
conda activate test
Controlling the install location
To control where the conda install ends up (perhaps to put it on a filesystem that's backed up, or conversely a scratch filesystem to save space) use the -p flag instead of -n to give the path to where the environment should be installed.
conda create -p /scratch/fjc55/condatest scipy
To install a Conda environment onto a filesystem shared from one of the local fileservers, add the --copy flag. Conda normally works by setting up symbolic links, but the fileservers do not support symbolic links.
conda create --copy -p /home/fjc55/nethome/condatest
Adding more packages
After the environment is created it's possible to add extra packages to it
conda install -n test flask
Conda-forge
As well as the long list of packages that come with the main Anaconda installation there is also a huge repository of useful 3rd party packages at Conda Forge. To install one of those packages pass '-c conda-forge' to 'conda install' to select the Conda Forge repository. For example
conda install -c conda-forge iris
This is the best way to get access to packages such as cfunits, esmp, orange, iris, iris-grib, eofs, pyke
Searching and installing specific versions
It's possible to search for packages on the different repositories:
conda search flask conda search -c conda-forge flask
and then install a particular version
conda install -n test flask=0.12.2
What if the package I need isn't available for conda?
You can still run pip inside a conda environment to install other packages. The only problem with this is that it can make the environment difficult to reproduce, because conda can't manage pip packages. If you need to use pip within conda it's best to set up a new environment just for the project that needs pip, install all the conda packages you need first into that environment, and only then run pip to intall the missing ones. Keep a separate record of what packages you installed using pip because conda cannot track these.
Scripts
Start your scripts with
#!/usr/bin/env python
and they'll use the currently active conda environment not the system Python