IT Support: CoE CIS Tech

IT Support: CoE CIS Tech

Providing Community, Instructional, and Research IT Support

Menu

  • Home: Unit Support
    • College of Engineering
      • Applied Engineering & Physics
      • Biological & Environmental Engineering
      • Biomedical Engineering
      • Chemical & Biomolecular Engineering
      • Civil & Environmental Engineering
      • Earth & Atmospheric Sciences
      • Electrical & Computer Engineering
      • Materials Science Engineering
      • Mechanical & Aerospace Engineering
      • Operations Research & Information Engineering
    • Cornell Ann S. Bowers College of Computing and Information Science
    • Cornell Tech Campus
  • Getting Started
    • Onboarding New Hires
    • Get Connected: Wired
    • Get Connected: Wirless
    • Printing: Ithaca
    • Printing: Tech Campus
    • Connect Remotely: VPN
    • Remote and Hybrid Work
    • Available Software
    • Two Step Login
    • Community IT Support
    • Staff IT@Cornell
    • Faculty IT@Cornell
    • Students IT@Cornell
    • Visitor & Alumni IT@Cornell
    • New Employee Guide
  • Instructional IT Support
    • Available Software
    • Azure Dev Tools for Teaching
    • Classroom Support
    • Distance/Remote Classes
    • Github
    • Instructional Labs
    • Loaner Equipment
    • Video Conferencing
    • CU Teaching Resources
    • IT@Cornell Faculty Resources
  • Research Computing Support
    • G2 GPU Cluster
    • Magma CPU Cluster
    • Data Security Plan (DSP)
    • Data Storage
    • Github
    • Server Configuration & Hosting
    • Terminal Login Nodes
    • Cloud Services
  • Quick Links
    • Contact ITSG
    • Available Software
    • Azure Dev Tools for Teaching
    • Cornell Drop Box
    • Cornell Box
    • Exchange Account Manager
    • Governance Policies
    • Identity Management
    • Outlook Web Access
    • Phishing Email Examples
    • IT Policies

Using a virtual environment in the G2 cluster

Contents

  • 1 Check to see that conda is in your PATH
  • 2 Create a virtual environment
  • 3 List your virtual environments
  • 4 Activate a virtual environment
  • 5 Install additional Python packages into a virtual environment
  • 6 List packages installed in a virtual environment
  • 7 Deactivate a virtual environment
  • 8 Delete a virtual environment
  • 9 Example of creating and moving around in a virtual environment
  • 10 Additional information

Check to see that conda is in your PATH

  • In a terminal enter conda -V
  • If conda is in your PATH you should see something similar to the following
netid@g2-login-01:~$ conda -V
conda 4.10.3
  • If the conda command is not found, you will need to add it to your PATH by issuing the following command (which is only good for the current shell) or append your .bashrc file with the following:
netid@g2-login-01:~$ export PATH=/share/apps/anaconda3/2021.05/bin:$PATH
  • or issue the conda init command below
netid@g2-login-01:~$ /share/apps/anaconda3/2021.05/bin/conda init
  • This conda init command places code in your . bashrc file that modifies, among other things, the PATH environment variable by prepending it to the path of the base conda environment
  • You must log out and log back in to cause the new code in .bashrc to be referenced
    • Note – the command prompt will change to indicate which conda environment you are currently in by prepending (base) – this is the default environment that includes a Python installation and some core system libraries and dependencies of Conda
(base) netid@g2-login-01:~$

Create a virtual environment

  • In a terminal enter the following where virt_env_name is what you want to name your virtual environment and replace x.x.x with the version of Python you want to use
netid@g2-login-01:~$ conda create -n virt_env_name python=x.x.x
  • To see a list of available Python versions, enter the following
netid@g2-login-01:~$ conda search "^python$"
  • Press y or hit enter to proceed
  • This will install the Python version and all the associated anaconda packaged libraries at
    • /home/netid/.conda/envs/virt_env_name

List your virtual environments

  • To see a list of all of your virtual environments, enter the following in a terminal
netid@g2-login-01:~$ conda info --envs or conda info -e

Activate a virtual environment

  • To activate or switch into a virtual environment type the following where virt_env_name is the name you gave to your virtual environment when it was created
netid@g2-login-01:~$ conda activate virt_env_name
  • Activating a conda environment modifies the PATH and shell variables to point to the specific isolated Python set-up you created
    • Note – the command prompt will change to indicate which conda environment you are currently in by prepending (virt_env_name)
(virt_env_name) netid@g2-login-01:~$

Install additional Python packages into a virtual environment

  • To install additional packages to your virtual environment, enter the following command where virt_env_name is the name of the environment you want to modify and [package] is the name of the package you want to install
netid@g2-login-01:~$ conda install -n virt_env_name [package]
  • Failure to specify “-n virt_env_name” will cause conda to attempt to install the package to the root Python installation located at /share/apps/anaconda3/2021.05 but users do not have write permissions to this directory so it will fail with
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.

List packages installed in a virtual environment

  • To list all packages in a virtual environment, enter the following command where virt_env_name is the name of the environment you want to check on
netid@g2-login-01:~$ conda list -n virt_env_name

Deactivate a virtual environment

  • To end a session in the current virtual environment, enter the following
netid@g2-login-01:~$ source deactivate
  • There is no need to specify the virtual environment name – the virtual environment currently active will simply be deactivated and the PATH and shell variables will be returned to normal

Delete a virtual environment

  • To delete a virtual environment, enter the following, where virt_env_name is the name of the virtual environment you want to delete
netid@g2-login-01:~$ conda remove -n virt_env_name --all
  • Press y or hit enter to proceed

Example of creating and moving around in a virtual environment

  • Create a virtual environment named pytorch using python v3.7.2 and add the pytorch and tk packages (and all dependencies) to the environment
netid@g2-login-01:~$ conda create -n pytorch python=3.7.2 pytorch tk
netid@g2-login-01:~$ conda activate pytorch
(pytorch) netid@g2-login-01:~$ which python
/home/netid/.conda/envs/pytorch/bin/python
(pytorch) netid@g2-login-01:~$ python -V
Python 3.7.2
(pytorch) netid@g2-login-01:~$ conda deactivate
netid@g2-login-01:~$

Additional information

  • The official documentation for Conda can be found here

 


Learn more about the ITSG

IT Maintenance and Alerts

Sitemap

IT@Cornell Services

Request IT Help

Submit Ticket

Search this site

CIT Service Alerts

https://itservicealerts.hosting.cornell.edu/allalerts

Academic Units

  • College of Engineering
  • Cornell Ann S. Bowers College of Computing and Information Science
  • Cornell Tech Campus

IT Staff

  • Login to edit content
If you have a disability and are having trouble accessing information on this website or need materials in an alternate format, contact web-accessibility@cornell.edu for assistance.
Copyright © 2023 IT Support: CoE CIS Tech. Powered by WordPress. Theme: Accelerate by ThemeGrill.