Conda Environment Creation with Specific Python Versions [Step-by-Step]

Conda Environment With Specific Python Version

Creating a conda environment with a specific Python version is common in various fields like data science and machine learning, scientific computing, and bioinformatics. It ensures the compatibility and consistency of the project. Different projects or applications may have dependencies on a particular version of Python. Creating a conda environment with a defined Python version helps avoid unexpected errors or issues related to version dependencies.

What is Conda?

Conda is an open-source package management system and environment management system. It is widely used for installing, updating, and managing software packages and their dependencies. Conda is widely used in data science and machine learning fields due to its ability to handle library dependencies effectively. Conda allows the creation of different environments.

Also read: Check Anaconda Version on Windows 10 [4 Easy Methods]

Step-by-Step – Creating a Conda Environment with a Specific Python Version

Here we are using an ‘Anaconda navigator‘. It is used for launching and managing conda packages and environments.

  • After completing the installation of the Anaconda navigator. Open’ Anaconda Navigator‘, and you can see the interface of Anaconda Navigator.
Conda Pg

As shown in the above image, you can see the interface of ‘Anaconda Navigator‘.
Also, you can directly use an ‘Anaconda prompt‘. Simply search an anaconda prompt in the search bar and open it.

  • Here we will create an environment with a specified Python version. To create a conda environment of a defined Python version, open the Anaconda Navigator, and on the left side you can see the ‘environments’ click on it. It will display the environments as shown below.
Conda Env

Here we have only one ‘base (root)‘ environment. There is a button click on it, now you can see different options like open terminal, open with Ipython, and open with Jupyter Notebook.

Conda Playbutton

Now click on ‘Open Terminal‘, and then you can see a command prompt.

Conda Base Env

Here you can see a ‘base‘ environment and the path. If you open the terminal of another environment, you can see your environment name instead of the base.

This command prompt you can directly open using an ‘Anaconda prompt‘. To open an Anaconda prompt, search an anaconda prompt in the search bar and then open it.

Conda Search

This will open the command prompt with the base environment.

  • To create a Conda environment with a specific Python version use the following command:
conda create --name env1 python=3.7

This command is used to create an environment. Here ‘env1‘ is the name of the environment. You can replace ‘env1‘ with the actual name of your environment. ‘python=3.7‘ is the Python version of the env1 environment. Replace 3.7 with the Python version you want to create an environment. So we are creating an environment named ‘env1‘ with Python ‘3.7‘ version.

Conda Proceed

To proceed type ‘y‘ and press Enter.

Conda Env1 Done

Now we successfully create an environment with the Python ‘3.7‘ version. Now to activate the ‘env1‘ environment use the following command:

conda activate env1

The ‘conda activate env1’ command line is used to activate the ‘env1‘ environment that we have created.

After that also you can check the Python version using the following command:

python --version
Conda Pyversion

Here you can see the Python version is 3.7.16 of the ‘env1‘ environment.

  • In the Anaconda Navigator interface also you can see the env1 environment below the base (root).
Conda Pyenv1

Here on the left side, you can see we have created an ‘env1’ environment and here also you can see Python version is 3.7.16.

Also read: Python Anaconda Tutorial – Getting Started With Anaconda

Summary

Now we successfully created a conda environment with the specific Python version using above mentioned steps. Using the same process you can create environments like this with the specified Python versions you want to create to avoid the dependencies issues. You can use the Anaconda navigator interface or the Anaconda prompt to create the environment.

References

  • https://stackoverflow.com/questions/56713744/how-to-create-conda-environment-with-specific-python-version
  • https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html