Using Python at the Martinos Center

There is no longer a centrally maintained Python distribution at the Martinos Center. Each group (or user) is encouraged to create their own Python installation. This is most easily done using the Anaconda installer and conda tool to install the versions of modules that work for their group. But be aware of major "gotchas" as discussed below.

For generic python scripts, one can try the OS installed python. Be aware the default python in CentOS7 is python2 and in CentOS8/Rocky8 no binary named just "python" exists -- you must explictly run python3 or python2. This may mean you need to change the first line of python scripts you download from the internet that just have "python".

If you use Python at the Center, make sure to sign up for the martinos-python mailing list to receive updates regarding Python related issues at the center.

Resources for Learning Python

* Python Scientific Lecture Notes

* NumPy for Matlab Users

* The Boston Python User Group regularly holds meetings and organizes introductory Python classes

Installing a Custom Python for Yourself with Anaconda

Follow the direction at Installing Ananaconda. You can skip the Prerequisites part as it is done on all our systems.

Make sure NOT to install the distribution into your home directory as your home directory quota is too small. Various things conda/pip do will also write lots of data to your ~/.conda, ~/.cache/pip and ~/.local/share/python* directories so you may need to symlink these to group storage volumes with more space.

Also I strongly suggest NOT having your ~/.cshrc or ~/.bashrc initialize your Anaconda install immediately on login. Instead setup a shell alias to do that on demand in each shell/Terminal when you need it. Anaconda installs in PATHs can interfer with other Linux systems program or even prevent GUI login from working. NoMachine, VNC and OpenOffice are known to break when sourcing anaconda automatically depending on the packages installed in your environment.

Another option is set "auto_activate_base: false" in your ~/.condarc file.

Using venv module with OS installed python

Using the venv module with the system OS installed python is a simple and quick way to install modules with pip you need that have no complicated 3rd party dependencies. Here is an example of using this method to install jupyter:

 cd /vast/itgroup/raines
 mkdir jupyter
 python3 -m venv /vast/itgroup/raines/jupyter
 source /vast/itgroup/raines/jupyter/bin/activate
 pip3 install --upgrade pip
 pip3 install jupyterlab
 /vast/itgroup/raines/jupyter/bin/jupyter lab --no-browser 

Neuroimaging Python Modules

The following neuroimaging related modules are ones many users will want to install in their Anaconda distribution:

* mne-python for M/EEG analysis

* nibabel provides access to a large number of neuro-imaging file formats

* nitime for time-series analysis

* pydicom enables you to read, modify and write DICOM files with python code

* PySurfer for visualization and interaction with cortical surface representations of neuroimaging data from FreeSurfer (Requires using environment pysurfer in anaconda2.7)

* TensorFlow for machine learning (Requires using either the tensorflow or tensorflow-gpu environment in anaconda2.7)

Always prefer installing a module using the conda installer with a prebuilt package. If you cannot find one that then you can resort to building it with pip.

Run pip list to see a full list of modules

Anaconda is also a good way to install and run R