IMPORTANT:
- Due to restricted licensing, please refrain from using the Anaconda environment at Rutgers unless it is used as part of a course. To avoid license violations, anaconda.org may be blocked from CS machines. If you like the Anaconda environment, there is an open-source alternative called Miniforge you should consider.
- Due to specific pytorch requirements of specific OS and Cuda versions, the CS python environment may not run pytorch with GPU. To run pytorch with GPUs, please run your pytoch in the container.
- When running GPU jobs, we require that you use Slurm Job Scheduling software to run your GPU jobs on iLab Servers. No GPU will be available without it.
There are many Python Tools for Managing Virtual Environments. As commonly used in many tutorials and also used by a peer education institution in NJ, we recommend venv for our users. You are not limited to venv. As you get familiar with other options, you may choose whatever fits your needs, but please read the license carefully before using it to avoid issues.
Using Python with CS Preset venv Environments
The instructions below assume you are using a bash shell. If you do not use bash as your default shell, you must run and type bash
before activating the Python environment above.
As of Summer 2024, there are five preset Python venv environments for Python: 3.8 / 3.9 / 3.10 / 3.11, and 3.12. You need to activate the correct version to use it on CS machines. Warning: Python 3.8 (end-of-life Sept 2024) is provided just in case people are not ready to move to a newer version.
Why use a Python environment?
The best practice we recommend is to create your own Python environment for each project you work on, so you have all the flexibility to add any modules you like, and it won’t be affected by the software changes we do.
Activate/deactivate the Python environment of your choice
We only run actively supported Python. To activate:
- python 3.8 environment type: (Warning: end-of-life: Sept 2024)
source /common/system/venv/python39/bin/activate
- python 3.9 environment type: (Warning: end-of-life: Sept 2025)
source /common/system/venv/python39/bin/activate
- python 3.10 environment type:
source /common/system/venv/python310/bin/activate
- python 3.11 environment type:
source /common/system/venv/python311/bin/activate
- python 3.12 environment type:
source /common/system/venv/python312/bin/activate
To deactivate or exit your Python virtual environment, type:deactivate
Installed modules/packages
pip list
However, if you want to build an environment with the same contexts, you can use the file requirements.txt at the top level of the venv as a starting point. Some of the syntax is odd, but it works with pip install.
Missing packages/modules in the environment
- If your code needs different modules, consider creating your environment with your packages.
- If you want to start with the same packages we have, you can see the list of the packages we install in “/common/system/venv/python3XY/packages.txt” as a starting point. It is intended to be used with one “pip install” command per package. It will not work as a requirements file using -r
- If you need modules for a class or think certain modules should be part of our default environment, please let us know to request the module be installed. We will install these modules if they do not conflict with existing software in a few days or so. Please be aware that major changes that require major component upgrades, such as the CUDA version upgrade, will not be done mid-semester and will likely be done in the summer.
Creating your environment Using venv
To create your environment, you can follow the steps below.
Important Compatibility Issues
- If you plan to use your environment on multiple versions of UbuntuOS, please make sure you create it using the oldest version of UbuntuOS. The older version won’t be able to use the environment created using a newer Operating System. You can find out the version of OS you are running by typing:
lsb_release -a
- You can not mix the Operating System. Example: environment created on Ubuntu will not run on CentOS
- If you plan to use your environment on multiple versions of UbuntuOS, please make sure you create it using the oldest version of UbuntuOS. The older version won’t be able to use the environment created using a newer Operating System. You can find out the version of OS you are running by typing:
There are many ways to create a virtual environment. In this example, we will use venv. Note: for this to work, we assume you are using bash shell, and we are using Python. To create your python3.12 environment type:/usr/bin/python3.12 -m venv ~/mypython312
Once created, to activate it, type:source ~/mypython312/bin/activate
To add modules/packages, type: pip install packagename
For more info, see: Understanding Python virtual environments using venv and virtualenv
GPU Usage on CS Machines
- If your issue is older codes requiring a specific version of Python, older modules, and CUDA versions, please see the Cuda/AI Learning Tools page.
- If you need powerful GPUs on GPU Servers, we require that you use Slurm Job Scheduling software to run your GPU jobs on iLab Servers (iLab1-4, rLab1-6). No server GPU will be available without Slurm. Desktop GPU does not require Slurm and can be used for small jobs or testing.
Using Python in IDE.
Once your specific Python environment is activated, you may need an Integrated Development Environment (IDE) to simplify your tasks. Here is a list of a few popular and free Python IDEs:
- If you are doing data science, please see the Data Science Facility page for more details.
- vscode: a popular IDE with support in multiple languages. To run vscode, type:
code
- spyder: a nice advanced IDE for python. To run Spyder in your choice of Python environment type:
spyder
- pyCharm: a limited community edition of pycharm is available. To run it, type
pycharm
- eclipse: a common and popular IDE. To run Eclipse, type:
eclipse
or choose it from the Programming menu. - Jupyter Notebook (iPython): an interactive way to run Python code on a browser. If you are using your environment, install a package named jupyterlab before you can run jupyter. Jupyterlab is already installed in the CS preconfigured environment.
To run jupyter, you need to open a terminal, and depending on your session, you would choose one of the following options. If you are in:- Graphical Session like Weblogin.cs or Local login, X2GO, XRDP. Type:
jupyter notebook --ip=`hostname`
This will start the jupyter session and automatically open a browser for your graphical session. - Non Graphical session like ssh type:
jupyter notebook --ip=`hostname` --browser="none"
This starts a jupyter session and tells you to copy and paste the URL to your local browser.
NOTE: The ` ` around the hostname are backward quotes. The backward quote key is normally at the upper left of your keyboard. Important: Due to firewall restrictions, this URL is only accessible from the machine you run in this notebook. This means that accessing the URL from your computer browser won’t work. - Web-based Jupyter. We also have a 100% Web Based system you can run on your browser by going to jupyter.cs.rutgers.edu
- Graphical Session like Weblogin.cs or Local login, X2GO, XRDP. Type:
Using System Python
python3
Please be aware we don’t recommend you to use system Python because
1. It is not portable
2 A system update can break your code
3. It does not contain many modules.
The best practice is to create your own or use an existing environment.
pip install module_name --user
The module is installed in your home directory in a hidden directory, for example, for python3.10, ~/.local/lib/python3.10/.
Storage Issue
If you have a big project or are in a tight space, you can move your local Python modules to another place. User Python modules are stored in the ~/.local folder by default. To move it to /common/users disk where you have 100GB of quota as follows:mv ~/.local /common/users/~your_netid/local
And create a soft link to your home directory for ~/.local using:ln -s /common/users/~your_netid/local ~/.local
Removing your existing Anaconda settings
When Anaconda was set up initially, it added a code section in your~/.bashrc
To clean up,
- Edit your
~/.bashrc
and remove this line
- Edit your
export PATH="$PATH:/koko/system/anaconda/bin"
- Remove the anaconda section as shown below:
# <<< conda initialize >>> ... ... # <<< conda initialize <<<
- Logout and login again
Further reading:
- Cuda/AI Learning Tools in CS Linux systems.
- Scheduler for Long GPU Jobs
- Using Virtual Environments in Jupyter Notebook and Python
- Jupyter Notebook for Beginners: A Tutorial
- Adding An Environment to Jupyter Notebooks
- 10 tips on using Jupyter Notebook