Difference between revisions of "Python on the CS Webservers"

Line 5: Line 5:
 
== Python Versions ==
 
== Python Versions ==
  
The webservers have both Python 3 and Python 2 available.  As of February 2021, the webservers are specifically using '''''Python 3.6'''''.  This is ''different'' from the [[:Category:Linux Clients|Linux clients]], which use a ''newer'' version.  If you're writing programs to run on one of the department webservers, '''we recommend you restrict those programs to use only features available in the webservers' version of Python 3.'''
+
The web servers have both Python 3 and Python 2 available.  As of February 2021, the web servers are using '''''Python 3.6''''' by default.  This is ''different'' from the [[:Category:Linux Clients|Linux clients]], which use a ''newer'' version. (As of fall 2025, the Linux clients use Python 3.13 by default.) If you're writing programs to run on one of the department web servers, '''we recommend you restrict those programs to use only features available in the web servers' version of Python 3.'''
  
The default Python version (what you get when you run the <code>python</code> program) is Python 3If you want Python 2, you must specify it explicitly by using <code>python2</code> at the top of your program.  Python 2 will be removed from our web servers at some future date no later than the summer of 2029.  (Note that Python2 will not be on our Linux clients after summer 2025.)
+
The web servers have several other versions of Python ''available''The Python versions available on both the web servers and the Linux clients are:
  
It's good practice to explicitly use <code>python3</code> when you intend to use Python 3.  Using <code>python</code> by itself is only recommended [https://www.python.org/dev/peps/pep-0394/ in a handful of situations] that mostly don't apply to our webservers.
+
* Python 3.6 (default on the web servers)
 +
* Python 3.9
 +
* Python 3.11
 +
* Python 3.12
 +
* Python 3.13 (default on the Linux clients)
 +
 
 +
The version of Python used for your programs will depend on what interpreter you call at the top of your program.  If you use {{code|#!/usr/bin/env python}} or {{code|#!/usr/bin/env python3}}, you will get the default Python for the system (which, again, will be different between the web server and the Linux client you can log in to).  If you use {{code|#!/usr/bin/env python2}}, you will get Python 2.7 on the web server and the program will not work on our Linux clients.  You can also give the precise version of Python you want; for example, {{code|#!/usr/bin/env python3.11}} will use Python 3.11 on both the web server and the Linux clients.
 +
 
 +
(It's good practice to explicitly use {{code|python3}} when you intend to use Python 3.  Using {{code|python}} by itself is only recommended [https://www.python.org/dev/peps/pep-0394/ in a handful of situations] that mostly don't apply to our web servers.)
  
 
== Python Packages ==
 
== Python Packages ==

Revision as of 18:43, 1 October 2025

Python is supported as a CGI program on the CS Department webservers, but there are a few things you should know about it.

You may also want to read about Python on the CS Linux Clients.

Python Versions

The web servers have both Python 3 and Python 2 available. As of February 2021, the web servers are using Python 3.6 by default. This is different from the Linux clients, which use a newer version. (As of fall 2025, the Linux clients use Python 3.13 by default.) If you're writing programs to run on one of the department web servers, we recommend you restrict those programs to use only features available in the web servers' version of Python 3.

The web servers have several other versions of Python available. The Python versions available on both the web servers and the Linux clients are:

  • Python 3.6 (default on the web servers)
  • Python 3.9
  • Python 3.11
  • Python 3.12
  • Python 3.13 (default on the Linux clients)

The version of Python used for your programs will depend on what interpreter you call at the top of your program. If you use #!/usr/bin/env python or #!/usr/bin/env python3, you will get the default Python for the system (which, again, will be different between the web server and the Linux client you can log in to). If you use #!/usr/bin/env python2, you will get Python 2.7 on the web server and the program will not work on our Linux clients. You can also give the precise version of Python you want; for example, #!/usr/bin/env python3.11 will use Python 3.11 on both the web server and the Linux clients.

(It's good practice to explicitly use python3 when you intend to use Python 3. Using python by itself is only recommended in a handful of situations that mostly don't apply to our web servers.)

Python Packages

The set of Python packages installed on the webservers is fairly minimal. If you need a package that's not installed, you should first try installing it yourself into your home directory, using our self-installation instructions. If that does not work, you can contact us at support@cs.jhu.edu for assistance, but be aware that we are not be able to install every requested package.

Deployment Options

For technical reasons, we do not support WSGI. You will have to run your Python programs as either CGI or FastCGI programs. (Most major Python web frameworks support FastCGI deployment; see their documentation for details.)