Running Python on Linstat

Python and Jupyter Notebook are available on Linstat. This article will show you how to set them up and use them.

Setting Up

Some setting up is required before you can (easily) run Python or Jupyter Notebook. We've created a script that does this for you, so all you need to do is log into Linstat and run:

setup_python

You then need to log out of Linstat and log back in so the new settings can take effect.

Running Jupyter Notebook

To run Jupyter Notebook, type:

jupyter notebook

This will first start a local web server that will do the actual work and then start a Chromium web browser (the open source version of Chrome) to interface with it. When you're done using Jupyter Notebook, you need to both close the web browser and shut down the web server. You can close the web browser in the usual way by closing its window. Then close the web server by pressing Ctrl-c. If you started Jupyter in the background or no longer have the session you started it in available, you can shut it down with:

jupyter notebook stop

Jupyter will start in your current working directory. Note that Jupyter can only see files and directories that are underneath the directory that it starts in, so make sure you're in or above the directory you want to work in before you start Jupyter. For example, if you start Jupyter in your home directory (the initial working directory when you log in) it will only be able to see files and directories in your home directory. If you want to work with files in a project directory, cd to that directory before starting Jupyter.

Running Python Scripts

You can run a Python script (.py file) by typing:

python myscript.py &

Where myscript should be replaced by the actual name of your script. This will put the job in the background, which means you can do other work with your Linux session or log out completely and your job will continue running. For more information, see Managing Jobs on Linstat.

Python distinguishes between packages that are installed globally (meaning all users of a given computer have access to them) and packages that are installed for a particular user. Linstat has all the packages that are part of the Anaconda distribution installed globally, including pandas, matplotlib, numpy, scipy and many others. Individual users cannot install packages globally, or change packages that were installed globally. However, users can install packages for themselves, including updated versions of globally installed packages.These packages will be stored in your home directory.

Packages should be installed using pip. To install a package for yourself type:

pip install --user packagename

where packagename should be replaced by the name of the package you want to install (for example, pip install --user pandas-datareader).

You can install more current versions of globally installed packages with:

pip install --user --upgrade packagename

You should only do so, however, if you need the latest version of a package immediately, as packages can take substantial space in your home directory. SSCC staff update the Python installation on Linstat each semester.

Last Revised: 9/28/2018