Differences between revisions 19 and 38 (spanning 19 versions)
Revision 19 as of 2013-03-23 09:39:21
Size: 19524
Editor: MartinLuessi
Comment:
Revision 38 as of 2023-10-18 18:19:32
Size: 4447
Editor: PaulRaines
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Scientific Python Mode in the NMR Center =
= Using Python at the Martinos Center =
Line 5: Line 4:
There are currently two scientific Python installations available at the Martinos Center. The more recent instillation is based on the
[[http://enthought.com/products/epd.php | Enthought Python Distribution (EPD)|target="_blank"]]. Users of the older
[[DevelopersGuide/NMRCenterPython/UsersGuide#legacy_python| "Legacy Scientific Python Installation"]] are encouraged to switch to the
EPD based installation, as it is more actively supported and contains more up to date packages.
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.
Line 10: Line 6:
If you use Python, make sure to sign up for the
[[https://mail.nmr.mgh.harvard.edu/mailman/listinfo/martinos-python | martinos-python mailing list | target="_blank"]] to receive updates regarding
the Python installation and discuss Python related issues.
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".
Line 14: Line 8:
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.
Line 15: Line 10:
== EPD Based Scientific Python Installation ==
<<Anchor(epd_python)>>
== Resources for Learning Python ==
* [[http://scipy-lectures.github.com|Python Scientific Lecture Notes]]
Line 18: Line 13:
=== Getting Started === * [[http://www.scipy.org/NumPy_for_Matlab_Users|NumPy for Matlab Users]]
Line 20: Line 15:
On CentOS 5/6 (64-bit) do the following to enable the EPD based Python installation * 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:
Line 23: Line 31:
setenv PATH /usr/pubsw/packages/python/epd/bin:${PATH}  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
Line 26: Line 40:
or if you use Bash 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.
Line 28: Line 42:
{{{
export PATH=/usr/pubsw/packages/python/epd/bin:${PATH}
}}}
== Neuroimaging Python Modules ==
The following neuroimaging related modules are ones many users will want to install in their Anaconda distribution:
Line 32: Line 45:
After this, you can run Python scripts by typing something like * [[http://martinos.org/mne/index.html|mne-python]] for M/EEG analysis
Line 34: Line 47:
{{{
 python my_script.py
}}}
* [[http://nipy.sourceforge.net/nibabel|nibabel]] provides access to a large number of neuro-imaging file formats
Line 38: Line 49:
To start an interactive Python ([[http://ipython.org | IPython | target="_blank" ]]) shell type * [[http://nipy.sourceforge.net/nitime|nitime]] for time-series analysis
Line 40: Line 51:
{{{
 ipython
}}}
* [[http://code.google.com/p/pydicom|pydicom]] enables you to read, modify and write DICOM files with python code
Line 44: Line 53:
For an integrated development environment specifically created for scientific Python type
(in a bash/tcsh, not IPython)
* [[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)
Line 47: Line 55:
{{{
 spyder &
}}}
* [[http://tensorflow.org|TensorFlow]] for machine learning (Requires using either the '''tensorflow''' or '''tensorflow-gpu''' environment in anaconda2.7)
Line 51: Line 57:
this will start [[http://code.google.com/p/spyderlib | Spyder | target="_blank" ]], which lets
you edit, run, and debug Python scripts. For new Python users, the built in help is a also very useful.
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'''.
Line 54: Line 59:
{{attachment:spyder_screenshot_small.png}} Run '''pip list''' to see a full list of modules
Line 56: Line 61:
=== Resources for Learning Python ===

* [[http://scipy-lectures.github.com | Python Scientific Lecture Notes | target="_blank"]]

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

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

=== Available Python Modules ===

[[http://enthought.com/products/epd.php | EPD |target="_blank"]] comes with a large number of Python modules;
an exhaustive list can be found [[http://enthought.com/products/epdlibraries.php | here | target="_blank"]].
In addition, the following neuroimaging related modules are installed:

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

* [[http://nipy.sourceforge.net/nibabel | nibabel | target="_blank"]] provides access to a large number of neuro-imaging file formats
 
* [[http://nipy.sourceforge.net/nitime | nitime | target="_blank"]] for time-series analysis

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

* [[http://pysurfer.github.com | PySurfer | target="_blank"]] for visualization and interaction with cortical surface representations of neuroimaging data from FreeSurfer

If you know of other modules that should be made available to all users, send an e-mail to the [[https://mail.nmr.mgh.harvard.edu/mailman/listinfo/martinos-python | martinos-python mailing list | target="_blank"]]

=== EPD Versions and Installed Modules ===

The following table aims to give a complete list of all installed EPD versions and modules. The currently stable version is '''epd-7.2-2-rh5-x86_64'''. A different version
can used by typing

{{{
setenv PATH /usr/pubsw/packages/python/${EPD_VERSION}/bin:${PATH}
}}}

where EPD_VERSION is one of the installed EPD versions.

||''' Module '''|| ''' epd-7.0-2-rh5-x86_64 '''|| ''' epd-7.1-1-rh5-x86_64 '''|| ''' epd-7.2-2-rh5-x86_64 '''|| ''' epd-7.3-1-rh5-x86_64 '''||
|| [[http://biopython.org/wiki/Main_Page | Bio | target="_blank"]] || 1.56 || 1.57 || 1.58 || 1.59 ||
|| [[http://biopython.org/wiki/BioSQL | BioSQL | target="_blank"]] || ? || ? || ? || ? ||
|| [[https://www.dlitz.net/software/pycrypto | Crypto | target="_blank"]] || 2.3 || 2.3 || 2.4.1 || 2.4.1 ||
|| [[http://www.cython.org | Cython | target="_blank"]] || 0.14.1 || 0.14.1 || 0.15.1 || 0.16 ||
|| [[http://ipython.org | IPython | target="_blank"]] || 0.10.1 || 0.11 || 0.12 || 0.12.1 ||
|| [[http://pyopengl.sourceforge.net | OpenGL | target="_blank"]] || 3.0.1 || 3.0.1 || 3.0.1 || 3.0.1 ||
|| [[http://packages.python.org/pyOpenSSL | OpenSSL | target="_blank"]] || 0.11 || 0.12 || 0.12 || 0.12 ||
|| [[http://www.pythonware.com/products/pil | PIL | target="_blank"]] || 1.1.7-3 || 1.1.7-3 || 1.1.7-3 || 1.1.7-3 ||
|| [[http://www.pyside.org | PySide | target="_blank"]] || || 1.0.3 || 1.1.0 || 1.1.0 ||
|| [[http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/cluster/software.htm#pycluster | Pycluster | target="_blank"]] || 1.50-2 || 1.50-3 || 1.50-4 || 1.50-4 ||
|| [[http://www.scons.org | SCons | target="_blank"]] || 2.0.1 || 2.0.1 || 2.0.1 || 2.0.1 ||
|| [[http://simpy.sourceforge.net/ | SimPy | target="_blank"]] || 2.1.0-2 || 2.1.0-2 || 2.2 || 2.2 ||
|| [[http://pypi.python.org/pypi/AppInst | appinst | target="_blank"]] || 2.0.4-1 || 2.1.0-1 || 2.1.0-1 || 2.1.1-1 ||
|| [[https://github.com/enthought/apptools | apptools | target="_blank"]] || || 4.0.0 || 4.0.1 || 4.1.0 ||
|| [[https://github.com/ilanschnell/bitarray | bitarray | target="_blank"]] || 0.3.5 || 0.3.5 || 0.3.5 || 0.8.0 ||
|| [[https://github.com/enthought/blockcanvas | blockcanvas | target="_blank"]] || || 4.0.0 || 4.0.1 || 4.0.1 ||
|| [[https://github.com/ilanschnell/bsdiff4 | bsdiff4 | target="_blank"]] || || || 1.0.1 || 1.1.1 ||
|| [[https://github.com/GaelVaroquaux/canica | canica | target="_blank"]] || 0.0.0-py2.7 || || || ||
|| [[http://code.enthought.com/projects/chaco | chaco | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[http://code.enthought.com/projects/code_tools.php | codetools | target="_blank"]] || || 4.0.0 || 4.0.0 || 4.0.0 ||
|| [[http://nedbatchelder.com/code/coverage | coverage | target="_blank"]] || 3.4 || 3.5 || 3.5.1 || 3.5.1 ||
|| [[http://pydap.org/ | dap | target="_blank"]] || ? || ? || ? || ||
|| [[http://labix.org/python-dateutil | dateutil | target="_blank"]] || 1.5 || 1.5 || 1.5 || 1.5 ||
|| [[http://code.google.com/p/pydicom | dicom | target="_blank"]] || 0.9.6 || 0.9.6 || 0.9.6 || 0.9.7 ||
|| [[http://docutils.sourceforge.net/ | docutils | target="_blank"]] || 0.7 || 0.7 || 0.8.1 || 0.8.1 ||
|| [[https://github.com/enthought/enstaller | egginst | target="_blank"]] || ? || ? || ? || ? ||
|| [[http://code.enthought.com/projects/enable | enable | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[https://github.com/enthought/enaml | enaml | target="_blank"]] || || || || 0.2.0-1 ||
|| enamldoc || || || || ? ||
|| [[https://github.com/enthought/encore | encore | target="_blank"]] || || || || 0.2-2 ||
|| [[https://github.com/enthought/enstaller | enstaller | target="_blank"]] || 4.3.1 || 4.4.0 || 4.4.1 || 4.5.0 ||
|| [[http://code.enthought.com/projects/envisage/ | envisage | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[http://epydoc.sourceforge.net | epydoc | target="_blank"]] || 3.0.1 || 3.0.1 || 3.0.1 || 3.0.1 ||
|| [[http://code.enthought.com/projects/ets_dev_tools.php | etsdevtools | target="_blank"]] || || 4.0.0 || 4.0.0 || 4.0.0 ||
|| [[http://foolscap.lothar.com/trac | foolscap | target="_blank"]] || 0.6.1 || 0.6.1 || 0.6.2 || 0.6.3 ||
|| [[http://fwrap.sourceforge.net/ | fwrap | target="_blank"]] || 0.1.1-1 || 0.1.1-2 || 0.1.1-3 || 0.1.1-3 ||
|| [[https://github.com/enthought/graphcanvas | graphcanvas | target="_blank"]] || || 4.0.0 || 4.0.0 || 4.0.0 ||
|| [[http://mercurial.selenic.com/wiki/NotifyExtension | hgext | target="_blank"]] || ? || || || ||
|| [[http://code.google.com/p/html5lib/ | html5lib | target="_blank"]] || 0.90 || 0.90 || 0.90 || 0.90 ||
|| [[http://code.google.com/p/httplib2/ | httplib2 | target="_blank"]] || $Rev: 259 $ || $Rev: 259 $ || $Rev: 259 $ || ||
|| [[http://jinja.pocoo.org | jinja2 | target="_blank"]] || 2.5.5 || 2.5.5 || 2.6 || 2.6 ||
|| [[http://packages.python.org/joblib/ | joblib | target="_blank"]] || 0.6.3 || 0.6.3 || 0.6.3 || 0.6.4 ||
|| [[http://jsonpickle.github.com/ | jsonpickle | target="_blank"]] || || || || 0.4.0 ||
|| kernmagic || || ? || ? || ? ||
|| [[http://bitbucket.org/kang/python-keyring-lib | keyring | target="_blank"]] || || || || 0.9-1 ||
|| kiva || || ? || ? || ? ||
|| [[http://lxml.de | lxml | target="_blank"]] || 2.3-1 || 2.3-1 || 2.3.2-1 || 2.3.4-1 ||
|| [[http://www.makotemplates.org | mako | target="_blank"]] || 0.4.1 || || || ||
|| [[http://pypi.python.org/pypi/MarkupSafe | markupsafe | target="_blank"]] || 0.12 || || || ||
|| [[http://matplotlib.sourceforge.net | matplotlib | target="_blank"]] || 1.0.1 || 1.0.1 || 1.1.0 || 1.1.0 ||
|| [[http://code.enthought.com/projects/mayavi/ | mayavi | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[http://pypi.python.org/pypi/Mercurial | mercurial | target="_blank"]] || 1.8.3-py2.7 || || || ||
|| [[http://matplotlib.github.com/basemap | mpl_toolkits | target="_blank"]] || ? || ? || ? || ? ||
|| netcdftime || 0.9.3 || || || ||
|| [[http://networkx.lanl.gov/ | networkx | target="_blank"]] || 1.4 || 1.5 || 1.6 || 1.6 ||
|| [[http://nipy.org/nibabel | nibabel | target="_blank"]] || 1.1.0 || 1.3.0 || 1.3.0 || 1.3.0 ||
|| [[http://nipy.sourceforge.net | nipy | target="_blank"]] || 0.1.2.dev || || 0.2.0rc1.dev1 || ||
|| [[http://nipy.org/nipype | nipype | target="_blank"]] || || || 0.5.3 || 0.6.0 ||
|| nisext || 1.1.0 || ? || 1.1.0 || 1.2.2 ||
|| [[http://nipy.org/nitime | nitime | target="_blank"]] || 0.3.dev || 0.3.1 || 0.3.1 || 0.4 ||
|| [[http://readthedocs.org/docs/nose/en/latest | nose | target="_blank"]] || 1.0.1 || 1.0.0 || 1.1.2 || 1.1.2 ||
|| [[http://code.google.com/p/numexpr/ | numexpr | target="_blank"]] || 1.4.2 || 1.4.2 || 2.0 || 2.0.1 ||
|| [[http://numpy.scipy.org | numpy | target="_blank"]] || 1.5.1 || 1.6.0 || 1.6.1 || 1.6.1 ||
|| [[http://bitbucket.org/ericgazoni/openpyxl/wiki/Home | openpyxl | target="_blank"]] || || || || 1.5.8 ||
|| osgeo || || || 1.8.1 || 1.8.1 ||
|| [[http://pandas.pydata.org | pandas | target="_blank"]] || 0.2 || 0.3.0 || 0.6.1 || 0.7.3 ||
|| [[http://www.lag.net/paramiko | paramiko | target="_blank"]] || 1.7.6 (Fanny) || 1.7.7.1 (George) || 1.7.7.1 (George) || 1.7.7.1 (George) ||
|| [[http://www.pip-installer.org | pip | target="_blank"]] || 1.0.1 || 1.0.2 || || ||
|| [[http://www.dabeaz.com/ply/ | ply | target="_blank"]] || 3.3-3 || 3.4-1 || 3.4-1 || 3.4-1 ||
|| [[http://code.google.com/p/pyamg | pyamg | target="_blank"]] || 1.0.0.dev || 1.0.0.dev || 1.0.0.dev || 2.0.4.dev ||
|| [[http://code.enthought.com/projects/traits_gui | pyface | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[http://www.stsci.edu/resources/software_hardware/pyfits | pyfits | target="_blank"]] || 2.4.0 || 2.4.0 || 3.0.3 || 3.0.6 ||
|| [[https://launchpad.net/pyflakes | pyflakes | target="_blank"]] || 0.4.0 || 0.4.0 || 0.5.0 || 0.5.0 ||
|| [[http://code.astraw.com/projects/motmot/wiki/pygarrayimage | pygarrayimage | target="_blank"]] || 0.0.7-4 || 0.0.7-4 || 0.0.7-4 || 0.0.7-4 ||
|| [[http://www.pyglet.org/ | pyglet | target="_blank"]] || ? || ? || ? || ? ||
|| [[http://pygments.org | pygments | target="_blank"]] || 1.4 || 1.4 || 1.4 || 1.4 ||
|| [[http://www.sourceforge.net/projects/pysclint | pyhdf | target="_blank"]] || 0.8.3-4 || 0.8.3-5 || 0.8.3-6 || 0.8.3-6 ||
|| [[http://code.google.com/p/pyproj/ | pyproj | target="_blank"]] || 1.8.7 || 1.8.9 || 1.8.9 || 1.9.0 ||
|| [[http://pytz.sourceforge.net | pytz | target="_blank"]] || 2010o || 2011g || 2011n || 2011n ||
|| [[http://www.prescod.net/pyximport | pyximport | target="_blank"]] || ? || ? || ? || ? ||
|| [[http://www.reportlab.com/ | reportlab | target="_blank"]] || ? || ? || ? || ? ||
|| [[http://rope.sf.net/ | rope | target="_blank"]] || 0.9.3 || 0.9.3 || 0.9.3 || 0.9.4 ||
|| [[http://scikits.appspot.com/scikits | scikits | target="_blank"]] || 0.9_git || 0.10 || ? || ? ||
|| [[https://github.com/enthought/scimath | scimath | target="_blank"]] || || 4.0.0 || 4.0.1 || 4.1.0 ||
|| [[http://www.scipy.org | scipy | target="_blank"]] || 0.9.0rc2 || 0.9.0 || 0.10.0 || 0.10.1 ||
|| [[http://pyserial.sourceforge.net | serial | target="_blank"]] || ? || ? || ? || ? ||
|| [[http://pypi.python.org/pypi/setuptools | setuptools | target="_blank"]] || 0.6 || 0.6 || 0.6 || 0.6 ||
|| shapelib || ? || ? || ? || ||
|| shapely || || || || 1.2.14 ||
|| skimage || || || 0.4.2 || 0.5 ||
|| [[http://scikit-learn.org | sklearn | target="_blank"]] || 0.9 || 0.10 || 0.9 || 0.11 ||
|| [[http://sphinx.pocoo.org | sphinx | target="_blank"]] || 1.0.7 || 1.0.7 || 1.1.3 || 1.1.2 ||
|| [[http://code.google.com/p/spyderlib | spyderlib | target="_blank"]] || 2.1.4 || 2.1.4 || 2.1.8 || 2.1.10 ||
|| [[http://code.google.com/p/spyderlib | spyderplugins | target="_blank"]] || ? || ? || ? || 2.1.10 ||
|| [[http://www.sqlalchemy.org | sqlalchemy | target="_blank"]] || 0.6.6 || 0.7.1 || 0.7.1 || 0.7.6 ||
|| [[http://www.sqlalchemy.org | sqlalchemy_nose | target="_blank"]] || ? || || || ||
|| [[http://statsmodels.sourceforge.net/ | statsmodels | target="_blank"]] || || || || 0.4.0 ||
|| [[http://pysurfer.github.com | surfer | target="_blank"]] || 0.1 || 0.1 || 0.1 || 0.3 ||
|| [[http://sympy.org | sympy | target="_blank"]] || 0.6.7 || 0.7.0 || 0.7.1 || 0.7.1 ||
|| [[http://www.pytables.org/ | tables | target="_blank"]] || 2.2.1 || 2.3b1.devpro || 2.3.1 || 2.3.1 ||
|| [[http://www.tornadoweb.org/ | tornado | target="_blank"]] || || || 2.1.1-1 || 2.2-1 ||
|| [[http://code.enthought.com/projects/traits | traits | target="_blank"]] || || 4.0.0 || 4.1.0 || 4.2.0 ||
|| [[https://github.com/enthought/traitsui | traitsui | target="_blank"]] || || 4.0.1 || 4.1.0 || 4.2.0 ||
|| [[https://github.com/enthought/mayavi | tvtk | target="_blank"]] || || ? || ? || ? ||
|| [[http://twistedmatrix.com/trac | twisted | target="_blank"]] || 10.2.0 || 11.0.0 || 11.1.0 || 12.0.0 ||
|| virtualenv_support || || ? || || ||
|| [[http://www.vtk.org/Wiki/VTK/Examples/Python | vtk | target="_blank"]] || 5.6.0-2 || 5.6.0-2 || 5.6.0-2 || 5.6.0-2 ||
|| [[http://wxpython.org | wxPython | target="_blank"]] || 2.8.10.1 || 2.8.10.1 || 2.8.10.1 || 2.8.10.1 ||
|| [[http://www.lexicon.net/sjmachin/xlrd.htm | xlrd | target="_blank"]] || 0.7.1-3 || 0.7.1-4 || 0.7.1-4 || 0.7.6-1 ||
|| [[https://secure.simplistix.co.uk/svn/xlwt/trunk | xlwt | target="_blank"]] || 0.7.2-3 || 0.7.2-3 || 0.7.2-3 || 0.7.3-1 ||
|| [[http://pyyaml.org | yaml | target="_blank"]] || 3.09 || 3.10 || 3.10 || 3.10 ||
|| [[http://www.zeromq.org/bindings:python | zmq | target="_blank"]] || 2.0.10-1 || 2.1.7 || 2.1.11 || 2.1.11 ||
|| [[http://docs.zope.org/zopetoolkit | zope | target="_blank"]] || ? || ? || ? || ? ||

== Legacy Scientific Python Installation ==
<<Anchor(legacy_python)>>

Scientific Python mode is now available in the following platform/os combinations in the NMR center

 * CentOS 64-bit
 * CentOS 32-bit
 * MacOSX Leopard (Intel)

The "system Python" ( the Python version which already exists in the system ) is not tampered with due to the following reasons:

  1. In CentOS systems, the Python version is very old ( 2.3.4 ) which prevents installation of many new modules essential for scientific computing in Python. However, a number of other system modules and programs are dependent on this version and it's best not to disturb this version.

  2. Leopard systems have a customized Python 2.5.x, which, again is a necessity for a number of modules. Again, best not to tamper with it.

  3. '''Isolation:''' The latest Python ( 2.6.3 ) and its associated modules are installed in /usr/pubsw/packages which are isolated from the system python and its modules. This configuration enables NMR center users to basically access both the versions of the Python and since both exist independently, they don't mess with each other.

=== Enabling the Scientific Python mode ===

By default, typing "python" to invoke the Python interpreter brings up the system Python interpreter which can be verified by looking at the version.

To enable the scientific python mode, users source the scientific python mode script in the following way :
{{{
source /usr/pubsw/packages/python/2.6/scientificpython/bin/tcsh_activate
}}}
'''Note:''' strongly recommended. this line can/should be put as an alias in one's ~/.cshrc in the following way:
{{{
alias pyactivate "source /usr/pubsw/packages/python/2.6/scientificpython/bin/tcsh_activate"
}}}
Once, this is done, the user can just type '''`pyactivate`''' to activate the scientific python mode and type '''`deactivate`''' to get back to the default ( normal system python mode )

In the scientific python mode, the prompt is preceded by the text `(scientificpython)`, which lets the user know that he/she is in the scientific python mode. The user can invoke the python interpreter by typing `python` and notice that the interpreter is now the latest Python's interpreter. Once the user deactivates the mode, the prompt is changed back to the default prompt.

'''Note:''' The sourcing script works under tcsh shell. Bash is currently unsupported but will be if there are enough users using bash.

=== List of installed modules ===

 * Python 2.6.3
 * Numpy 1.3.0
 * Scipy 0.7.1 (c)
 * matplotlib 0.99.1.1 ( `TkInter` backend in Mac platform and wxPython backend in CentOS platforms ) (c)
 * wxPython 2.8.10.1 ( only on CentOS platforms ) (c)
 * IPython 0.10
 * NetworkX 1.0rc1
 * nose 0.11.1
 * Sphinx 0.6.3
 * Cython 0.11.3
 * pynifti 0.20090303.1 (c)
 * SQLAlchemy 0.6.3
 * argparse 1.1
 * xlrd 0.7.1
 * xlwt 0.7.2
 * pysqlite 2.6.0 ( except CentOS 32-bit )
 * PyXML 0.8.4 (c)
 * pydicom 0.9.4-1
 * nibabel 1.0.0 ( cutting edge master branch Aug 27, 2010 )

 
'''Note :''' The list of modules indicated by (c) are compiled modules and the rest were installed using easy_install script.

=== Troubleshooting ===

 1. '''`pylab`''' doesn't start: This might be because there might be a stray `.matplotlibrc` file, which is already existing in your path preventing the standard backend to load. As an example, pylab can't be imported if the backend is `WXAgg` for Mac platforms or `TkAgg` for CentOS platforms. The fix is to comment out the line starting with `backend` in your `.matplotlibrc` ( usually in ~/matplotlib/matplotlibrc )

=== Behind the Scenes ===

( For advanced users )

A program called `virtualenv` is made use of to isolate the Pythons. virtualenv enables one to totally switch to a different Python with its own modules ( enabled by the switch --no-site-packages). So when the user sources the `tcsh_activate` script, what he/she is effectively doing is to prefix the system PATH, PYTHONPATH, module PATHs with the custom Python's paths and when the user `deactivate`s he/she gets back all the default paths. virtualenv takes care of this complex paths manipulation behind the scenes. It also makes the modules installation a breeze for the administrator.
Anaconda is also a good way to [[https://docs.anaconda.com/anaconda/packages/r-language-pkg-docs/|install and run R]]

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 

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:

* 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

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