How to Specify a Python Version in a Conda Environment?

Estimated read time 1 min read

To specify a Python version in a Conda environment, you can create a new environment or modify an existing one with the desired version of Python using the conda create or conda env update command.

  1. Creating a new environment:

To create a new environment with a specific version of Python, you can use the following command:

conda create --name myenv python=3.8

This creates a new environment called myenv with Python 3.8 installed.

  1. Updating an existing environment:

To update an existing environment with a specific version of Python, you can create an environment.yml file with the desired configuration and run the conda env update command. Here’s an example environment.yml file:

name: myenv
  - defaults
  - python=3.8

Save this file in your project directory and then run the following command:

conda env update --file environment.yml

This updates the myenv environment with Python 3.8.

You can then activate the environment with the following command:

conda activate myenv

This activates the myenv environment with the specified version of Python.

Note that when you create or update a Conda environment with a specific version of Python, Conda will also install any required packages and dependencies for that version of Python.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply