Differences between revisions 38 and 39
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Using Python at the Martinos Center =
<<TableOfContents(3)>>

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 [[https://mail.nmr.mgh.harvard.edu/mailman/listinfo/martinos-python|martinos-python mailing list]] to receive updates regarding Python related issues at the center.

== Resources for Learning Python ==
* [[http://scipy-lectures.github.com|Python Scientific Lecture Notes]]

* [[http://www.scipy.org/NumPy_for_Matlab_Users|NumPy for Matlab Users]]

* The [[http://meetup.bostonpython.com|Boston Python User Group]] regularly holds meetings and organizes introductory Python classes

== Installing a Custom Python for Yourself with Anaconda ==
Follow the direction at [[https://docs.anaconda.com/anaconda/install/linux/|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
}}}

Note that you will have to do the '''source''' line in other shells or in new logins. It is still best NOT to put this in your login scripts unless you know it will not interfer with other programs.

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

* [[http://martinos.org/mne/index.html|mne-python]] for M/EEG analysis

* [[http://nipy.sourceforge.net/nibabel|nibabel]] provides access to a large number of neuro-imaging file formats

* [[http://nipy.sourceforge.net/nitime|nitime]] for time-series analysis

* [[http://code.google.com/p/pydicom|pydicom]] enables you to read, modify and write DICOM files with python code

* [[http://pysurfer.github.com|PySurfer]] for visualization and interaction with cortical surface representations of neuroimaging data from FreeSurfer (Requires using environment '''pysurfer''' in anaconda2.7)

* [[http://tensorflow.org|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 [[https://docs.anaconda.com/anaconda/packages/r-language-pkg-docs/|install and run R]]
This page has been moved [[https://it.martinos.org/help/python|here]]

This page has been moved here

DevelopersGuide/NMRCenterPython/UsersGuide (last edited 2023-11-01 16:09:01 by PaulRaines)