DEV Community

hub
hub

Posted on

how to use Python virtual environments with conda - some notes

how to use Python virtual environments with conda, you can follow these steps:

Open your terminal or Anaconda prompt.

Create a new conda environment by typing the following command:

conda create --name env_name python=X.X

Replace env_name with the name you want to give to your environment and X.X with the version of Python you want to use. For example, to create an environment called my_env with Python 3.9, you would type:

conda create --name my_env python=3.9

Activate the environment by typing:

conda activate env_name

Replace env_name with the name of your environment. For example, to activate the my_env environment, you would type:

conda activate my_env

Install any packages you need for your project using conda install. For example, to install the pandas package, you would type:

conda install pandas

When you're finished working in the environment, you can deactivate it by typing:

conda deactivate

This will return you to your default system Python installation.

To delete the environment, you can use the following command:

conda env remove --name env_name

Replace env_name with the name of the environment you want to delete. For example, to delete the my_env environment, you would type:

conda env remove --name my_env

That's it! Using conda with Python virtual environments is a great way to keep your project dependencies organized and isolated.

Top comments (0)