Python

How to Create an Anaconda Python Virtual Environment Using a Specific Version of Python

In this article, we will show you how to create an Anaconda Python virtual environment using a specific version of Python. We will also show you how to activate and deactivate the newly created Anaconda Python virtual environment as well.

Topic of Contents:

  1. Opening the Anaconda Python Prompt/Shell/Terminal on Windows 10/11
  2. Opening the Anaconda Python Prompt/Shell/Terminal on Linux
  3. Creating an Anaconda Python Virtual Environment Using a Specific Python Version
  4. Activating the Newly Created Anaconda Python Virtual Environment
  5. Deactivating the Newly Created Anaconda Python Virtual Environment
  6. Conclusion

Opening the Anaconda Python Prompt/Shell/Terminal on Windows 10/11

To open the Anaconda Python prompt/shell/terminal on Windows 10/11, search for “apps: anaconda” from the start menu[1] and click on the “Anaconda Prompt” app[2].

The Anaconda Python prompt/shell/terminal should be opened.

A screenshot of a computer Description automatically generated

Opening the Anaconda Python Prompt/Shell/Terminal on Linux

To open the Anaconda Python prompt/shell/terminal on Linux, open a Terminal app and run the following command:

$ conda activate

The Anaconda Python prompt/shell/terminal should be opened.

Creating an Anaconda Python Virtual Environment Using a Specific Python Version

To create an Anaconda Python virtual environment like “tf-gpu” (let’s say) using a specific version of Python (i.e. Python 3.10), run the following command:

$ conda create --name tf-gpu python=3.10

Anaconda Python may need to install some extra packages to install the version of Python that you want to use for the new Anaconda Python virtual environment. To confirm the installation, press “y” and then press <Enter>.

The required Anaconda Python packages are being installed and a new Anaconda Python virtual environment is being created.

A screenshot of a computer program Description automatically generated

At this point, the required Anaconda Python packages should be installed and a new Anaconda Python virtual environment should be created.

A screenshot of a computer Description automatically generated

You can list all the available Anaconda Python virtual environments with the following command:

$ conda env list

As you can see, the newly created Anaconda Python “tf-gpu” virtual environment is on the list.

A computer screen with white text Description automatically generated

Activating the Newly Created Anaconda Python Virtual Environment

The default Anaconda Python virtual environment base is activated when you open the Anaconda Python prompt/shell/terminal.

To activate the newly created Anaconda Python “tf-gpu”virtual environment, run the following command:

$ conda activate tf-gpu

The Anaconda Python “tf-gpu” virtual environment should be activated.

A black and blue background with white text Description automatically generated

As you can see, Python 3.10.x is being used for the Anaconda Python “tf-gpu” virtual environment.

A black and white screen with white text Description automatically generated

Deactivating the Newly Created Anaconda Python Virtual Environment

To deactivate the Anaconda Python “tf-gpu” virtual environment, run the following command:

$ conda deactivate

The Anaconda Python “tf-gpu” virtual environment should be deactivated and the default Anaconda Python environment base should be activated.

A black and blue screen with white text Description automatically generated

Conclusion

In this article, we showed you how to create an Anaconda Python virtual environment using a specific version of Python. We also showed you how to activate and deactivate the newly created Anaconda Python virtual environment.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.