Difference between revisions of "Python on the CS Linux Clients"

(Created page with "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...")
 
(→‎Note: Python 2 is Deprecated: Python 2 removal date)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
All of the CS Department's [[:Category:Linux Clients|Linux clients]] have both Python 2.7 and Python 3 installed.  This page has some information about how Python works in our environment.
+
All of the CS Department's [[:Category:Linux Clients|Linux clients]] have both Python 3 and Python 2.7 installed.  The default version is Python 3.  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.  Official support for Python 2 ended in January 2020.  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 [https://docs.python.org/3/howto/pyporting.html port it to Python 3].
 +
 
 +
Python 3 has been the default version of Python on our systems since early 2020.  We expect to completely remove Python 2 from our Linux clients in the summer of 2025.
  
 
== Installing Python Packages ==
 
== Installing Python Packages ==
  
We try to have a good selection of the most-commonly-useful Python packages preinstalled on the Linux clients and available for both Python 2 and 3.  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.
+
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 ===
  
<tt>pip</tt> 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:
+
<code>pip</code> 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''
 
  pip install --user ''package''
  
For Python3, use <tt>pip3</tt> instead of <tt>pip</tt>.
+
If you need a Python 2 package, use <code>pip2</code> instead of <code>pip</code>.
  
 
Note that, for ugrad accounts, the package will count against your [[Disk Quotas|disk quota]].
 
Note that, for ugrad accounts, the package will count against your [[Disk Quotas|disk quota]].
Line 19: Line 27:
 
  pip uninstall ''package''
 
  pip uninstall ''package''
  
<tt>pip</tt> will figure out on its own that it was locally-installed.
+
<code>pip</code> will figure out on its own that it was locally-installed.
  
 
=== virtualenv ===
 
=== virtualenv ===
  
For complete control over what Python packages are available, you can use [https://virtualenv.pypa.io/en/stable/ 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 <tt>pip install --user</tt>).
+
For complete control over what Python packages are available, you can use [https://virtualenv.pypa.io/en/stable/ 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 <code>pip install --user</code>).
  
To use a virtual environment, pick a directory where it will keep its data and use the <tt>virtualenv</tt> 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:
+
To use a virtual environment, pick a directory where it will keep its data and use the <code>virtualenv</code> 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
 
  virtualenv ~/python/project-1
  
To start using the virtual environment, you must use one of the "activate" scripts in the environment's "<tt>bin</tt>" directory.  If you haven't changed your shell on our systems, use <tt>activate.csh</tt> .  If you're using bash, use <tt>activate</tt> .  Load the appropriate script with the <tt>source</tt> command:
+
To start using the virtual environment, you must use one of the "activate" scripts in the environment's "<code>bin</code>" directory.  If your login shell is bash or zsh, use <code>activate</code> .  If you're using csh or tcsh, use <code>activate.csh</code> . (See [[Shells Available for CS Accounts (bash, tcsh, etc.)#How to Tell What Shell You.27re Using|How to Tell What Shell You're Using]] if you're not sure what your shell is.) Load the appropriate script with the <code>source</code> command:
  
  source ~/python/project-1/bin/activate.csh
+
  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 "<tt>pip install ''package''</tt>" (without the "<tt>--user</tt>" parameter).
+
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 "<code>pip install ''package''</code>" (without the "<code>--user</code>" parameter).
  
To leave the virtual environment, simply use the <tt>deactivate</tt> command:
+
To leave the virtual environment, simply use the <code>deactivate</code> command:
  
 
  deactivate
 
  deactivate
Line 48: Line 56:
  
 
[[Category:Linux Clients]]
 
[[Category:Linux Clients]]
[[Category:Software]]
+
[[Category:Software Available On The CS Linux Clients]]

Latest revision as of 20:12, 14 August 2024

All of the CS Department's Linux clients have both Python 3 and Python 2.7 installed. The default version is Python 3. 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. Official support for Python 2 ended in January 2020. 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.

Python 3 has been the default version of Python on our systems since early 2020. We expect to completely remove Python 2 from our Linux clients in the summer of 2025.

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.