Running Python on Linstat

Python, Jupyter Notebook, PyCharm, and Spyder are available on Linstat. This article will show you how to use them, how to run Python scripts, and how to install Python packages on Linstat.

Jupyter Notebook

To run Jupyter Notebook, type:

sscc-jupyter

Jupyter Notebook consists of a local web server running on Linstat that does the actual work, and a user interface that runs in a web browser on your computer. In order to use it you must be on the SSCC network, so use VPN if necessary.

When you start Jupyter Notebook, it will print various messages ending with something similar to:

    To access the notebook, open this file in a browser:

        file:///home/r/rdimond/.local/share/jupyter/runtime/nbserver-836885-open.html

    Or copy and paste one of these URLs:

        http://linstat3.ssc.wisc.edu:8888/?token=53fcb4e2a0e6bbab6a9ec87fa0b3d0348d399363dea970c8

     or http://127.0.0.1:8888/?token=53fcb4e2a0e6bbab6a9ec87fa0b3d0348d399363dea970c8

Copy the URL that contains word "linstat" (in this case http://linstat3.ssc.wisc.edu:8888/?token=53fcb4e2a0e6bbab6a9ec87fa0b3d0348d399363dea970c8) and paste it in a browser running on your computer. 

When you're done using Jupyter Notebook, you need to close the web server by pressing Ctrl-c in your Linux session. 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.

PyCharm

To run the PyCharm development environment, type:

pycharm

Unfortunately performance tends to be poor. You may prefer to write your code using PyCharm on Winstat, save your scripts on the Linux file system (Z: and V:), and then run them on Linstat without using PyCharm.

Spyder

To run the Spyder development environment, type:

spyder

Unfortunately performance tends to be poor. You may prefer to write your code using Spyder on Winstat, save your scripts on the Linux file system (Z: and V:), and then run them on Linstat without using Spyder.

Running Python Scripts

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

python my_script.py &

Where my_script.py 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.

Installing Packages

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 package_name

where package_name 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 package_name

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.



KeywordsSSCC Linstat Python Jupyter Notebook Pycharm Spyder packages pip   Doc ID117328
OwnerRussell D.GroupSocial Science Computing Cooperative
Created2022-03-14 11:29:35Updated2022-04-12 11:05:03
SitesSocial Science Computing Cooperative
CleanURLhttps://kb.wisc.edu/sscc/running-python-on-linstat
Feedback  0   0