Python is a general purpose, interpretive programming language. It is useful for both small-scale scripting tasks and large scale applications. There are numerous packages available for Python, including many ideally suited for scientific computing. If any Python packages are missing, we also provide instructions on how to install packages in your own directories. Python can be run interactively and in batch. It can be integrated with other programming languages, including C, C++, R, Fortran and others.
Availability and Setup
Python 2.7.5 is the default version available installed with the operating system on the SCC. This does not contain many useful packages such as scipy and pandas and it is intended more for system administration purposes. We recommend using the module system to access newer versions of python (and python related packages). For new Python software development Python 3 should be used as Python 2 support has been officially ended by the Python language developers since January 1, 2020.
Running Python Interactively
Running Python interactively is quick and simple. Load the module for the version of python you want to use and run the command
scc1% module load python3/3.7.7 scc1% python Python 3.7.7 (default, May 21 2020, 14:57:43) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
The Python command prompt, >>>, signifies that you have successfully started the Python environment. To close the Python session, enter
exit()or press the key combination Ctrl-D
The SCC Python modules include the Spyder integrated development environment. This can be accessed using the SCC OnDemand site. Alternatively, when using a graphical session (such as an OnDemand desktop) it can be accessed by loading a Python module and entering the command as shown:
scc1% module load python3/3.7.7 scc1% spyder &
The SCC Python modules also include the Jupyter Notebook development environment. The recommended way is to access Jupyter Notebooks using the SCC OnDemand site. Alternatively, when using a graphical session (such as an OnDemand desktop) it can be accessed by loading a Python module and entering the command as shown. This will automatically launch the Firefox web browser on the SCC to display the notebook and will not use your local browser as is done when using Jupyter Notebooks directly through OnDemand:
scc1% module load python3/3.7.7 scc1% jupyter notebook
Typically Python is run serially (that is using one processor), and you should follow the standard batch submission instructions found on our Running Jobs documentation page to submit your Python jobs. In short, the best solution is to put your “python myscript.py” instruction in another file, a batch script, and then provide that script to qsub command.
Python has the
help() function, which prints the docstring (that is help information) for anything in python. For example the help information for the standard method
>>> help(len) Help on built-in function len in module __builtin__: len(...) len(object) -> integer Return the number of items of a sequence or mapping. >>>
Along with in depth online documentation, the Python website provides a comprehensive tutorial that has many examples. The Boston Python Meetup Group frequently presents a workshop and a series of tutorials (found in the Resources section of their workshop website) for users new to programming, and this is another good option for those wanting a gradual introduction.
Finally, as part of our RCS Online Code Examples section, we also have a number of Python code examples, both general including a “hello world” example and a set of examples from the tutorials we offer.