Skip to content

Python Anaconda Environments


Managing Python Packages with Anaconda on CS Servers

This guide provides instructions on how to configure and use Anaconda environments to install and manage Python packages on ODU CS department servers. Anaconda allows you to create isolated environments, preventing package conflicts and ensuring reproducibility of your Python projects.

Is Anaconda Available?

To check if Anaconda (or more specifically, the conda command) is installed and accessible on the server you are using, open a terminal and run:

conda -V
If you see a version number (e.g., conda 4.x.x), Anaconda is available.

Anaconda Not Found?

If the command is not found or you receive an error, Anaconda may not be installed on that particular server, or it might not be in your PATH. If you require Anaconda for your work on a CS server where it's unavailable, please email CS Systems Support at [root@cs.odu.edu](mailto:root@cs.odu.edu).

What is Anaconda/Conda?

Conda: Package and Environment Management

Conda is an open-source package management system and environment management system. It allows you to: * Install, run, and update Python packages and their dependencies. * Create isolated "environments" to manage different sets of packages for different projects, avoiding conflicts. * Easily switch between these environments. (Source: anaconda.com)


How to Use Conda Environments

The typical workflow involves creating an environment, installing packages into it, and then activating the environment to use those packages.

1. Creating a Virtual Environment

Creating a New Conda Environment

First, you need to create a new virtual environment. This isolates your project's dependencies.

  1. Use the following command:

    conda create --name <your_env_name>
    

    • Replace <your_env_name> with a descriptive name for your environment (e.g., my_project_env, data_analysis_env).
  2. Specify a Python Version (Optional but Recommended): To ensure your environment uses a specific version of Python, add the python argument:

    conda create --name <your_env_name> python=<version>
    

    • Example: conda create --name my_project_env python=3.9
  3. Conda will show you a list of packages that will be installed in the new environment. When prompted Proceed ([y]/n)?, type y and press Enter.

2. Installing Packages into an Environment

Installing Python Packages

Once your environment is created, you can install Python packages into it.

  1. Use the conda install command, specifying the environment name and the package(s) you want:

    conda install --name <your_env_name> <package_name>
    

    • Replace <your_env_name> with the name of your environment.
    • Replace <package_name> with the name of the Python package you want to install (e.g., numpy, pandas, scikit-learn).
    • You can install multiple packages at once: conda install --name my_project_env numpy pandas matplotlib
  2. Specify a Package Version (Optional): If you need a specific version of a package, you can specify it:

    conda install --name <your_env_name> <package_name>=<version>
    

    • Example: conda install --name my_project_env scipy=1.7.3
  3. Conda will resolve dependencies and show you what will be installed or updated. Confirm by typing y when prompted.

Alternative: Install Packages After Activating

You can also install packages after activating an environment (see next step). If the environment is active, you can omit the --name <your_env_name> flag:

# First, activate the environment
conda activate <your_env_name>
# Then, install packages
conda install <package_name>

3. Using the Environment

Using Your Conda Environment

To use the packages installed in your environment, you must first "activate" it.

  1. Activate the Environment:

    conda activate <your_env_name>
    

    • Replace <your_env_name> with your environment's name.
    • Your terminal prompt should change to indicate that the environment is active (e.g., (<your_env_name>) user@server:~$).
  2. Run Your Python Scripts: Once the environment is active, you can execute your Python scripts as you normally would. The python command will now use the Python interpreter and packages from your active Conda environment.

    python your_script.py
    

  3. Deactivate the Environment: When you are finished working in the environment, deactivate it to return to your base system environment:

    conda deactivate
    

    • Your terminal prompt will return to normal.

Further Documentation

📚 Official Conda Documentation

For more detailed information, advanced usage, and troubleshooting, refer to the official Conda documentation: conda.io/projects/conda/en/latest/index.html