4.1 Managing Python Versions#

Creating a Conda Environment with a Specific Python Version on Linux#

Conda is an environment and package manager that allows you to create isolated environments for different projects, specifying exact versions of Python and other packages needed. For detailed installation instructions for Conda, refer to the Conda documentation.

Create a New Conda Environment#

To create a new Conda environment with a specific version of Python, use the command:

conda create --name py3.10.4_clean python=3.10.4

This command creates a new environment named py3.10.4_clean, specifically with Python version 3.10.4. Replace 3.10.4 with any version of Python you require for your project.

Activate the Conda Environment#

With the environment created, you need to activate it to start using it. Activate your new environment with:

conda activate py3.10.4_clean

Activating the environment sets up your terminal to use the Python version and any packages installed in this isolated environment.

Deactivate the Environment#

When you’re finished with your work in the environment, you can deactivate it, returning your terminal to its base configuration:

conda deactivate

Listing All Available Conda Environments#

To view a list of all Conda environments available on your system, you can use the following command:

conda env list

or its shorthand version:

conda info --envs

This command will display a list of all Conda environments, showing their names and the paths to their directories.

Accessing the Python Executable Path#

Each environment listed by the conda env list command includes a path to its directory. This path is useful for accessing the Python executable specific to an environment. For instance, if you’re integrating tools, scripts, or IDEs with a specific environment, you might need to specify the path to the Python executable within that environment.

The path displayed next to each environment name leads directly to the environment’s root directory. Inside this directory, you can find the Python executable in the bin folder. For example, the path to the Python executable for an environment named py3.10.4_clean might look like this:

/home/username/miniconda3/envs/py3.10.4_clean/bin/python

This path allows you to invoke Python directly from that environment, ensuring that any Python scripts or commands are executed with the environment’s specific Python version and dependencies.

References#

Conda documentation