Difference between revisions of "Python on the CS Linux Clients"
m (→virtualenv) |
|||
Line 11: | Line 11: | ||
== Note: Change in Default Python Version == | == Note: Change in Default Python Version == | ||
− | + | In January 2020, we upgraded our Linux clients from Fedora 29 to Fedora 31. On our now-upgraded Fedora 31 systems, the <code>python</code> program is Python ''3.7''. If you need to, you can use <code>python2</code> to get Python 2.7. (You can also use <code>python3</code> to get Python 3.) The change in the default Python version may cause existing programs to break if they don't specify which Python version they want. You should explicitly name the Python your program expects by starting it with either: | |
#!/usr/bin/env python3 | #!/usr/bin/env python3 |
Revision as of 16:45, 3 February 2020
All of the CS Department's Linux clients have both Python 2.7 and Python 3 installed. This page has some information about how Python works in our environment.
You may also want to read about Python on the CS Webservers.
Note: Python 2 is Deprecated
Although Python 2.7 is installed on our systems, it should only be used when needed for compatibility with older programs. As of January 2020, official support for Python 2 has ended. New programs should use Python 3, and old Python 2 programs may not work properly. If a program does not work with Python 2, the solution is to port it to Python 3.
We plan to completely remove Python 2 from our Linux clients after the Fall 2020 semester.
Note: Change in Default Python Version
In January 2020, we upgraded our Linux clients from Fedora 29 to Fedora 31. On our now-upgraded Fedora 31 systems, the python
program is Python 3.7. If you need to, you can use python2
to get Python 2.7. (You can also use python3
to get Python 3.) The change in the default Python version may cause existing programs to break if they don't specify which Python version they want. You should explicitly name the Python your program expects by starting it with either:
#!/usr/bin/env python3
or
#!/usr/bin/env python2
Installing Python Packages
We try to have a good selection of the most-commonly-useful Python packages preinstalled on the Linux clients. It sometimes happens that people need one or more packages that aren't currently installed. Here's how you can get the packages you need.
pip
pip
is installed on our systems, so if you need a package (and if it's in the Python Package Index), you can install it for your own personal use with:
pip install --user package
If you need a Python 2 package, use pip2
instead of pip
.
Note that, for ugrad accounts, the package will count against your disk quota.
Removing a package you installed is as simple as:
pip uninstall package
pip
will figure out on its own that it was locally-installed.
virtualenv
For complete control over what Python packages are available, you can use virtualenv. It uses a directory to hold a complete set of packages that are entirely independent from whatever is installed in the system (or in your home directory via pip install --user
).
To use a virtual environment, pick a directory where it will keep its data and use the virtualenv
program to initialize the directory. For example, if you want to make a "project-1" environment and keep all of your environments in a "~/python" directory, you could do this:
virtualenv ~/python/project-1
To start using the virtual environment, you must use one of the "activate" scripts in the environment's "bin
" directory. If your login shell is bash or zsh, use activate
. If you're using csh or tcsh, use activate.csh
. (See How to Tell What Shell You're Using if you're not sure what your shell is.) Load the appropriate script with the source
command:
source ~/python/project-1/bin/activate
Your shell prompt will change to show the environment you're using. No packages will be available to start with, but you can install them with "pip install package
" (without the "--user
" parameter).
To leave the virtual environment, simply use the deactivate
command:
deactivate
If you have a ugrad account, you will need to make sure you don't exceed your disk quota.
Request Systemwide Installation
If the package is likely to be useful for a number of different people or if there's some reason you can't install it into your home directory, you can ask us to install it systemwide via our software installation request procedure.
Please note that, while we try to accommodate most requests, we cannot guarantee installation of any particular package.