How to use python virtual environment with conda
Milind Soorya / August 21, 2021
2 min read
In this tutorial I will show you how to setup python virtual environment. This process will work even if you are a mac, windows or linux user as we will be installing it using a popular software package manager called Anaconda.
A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
Conda is a popular opensource python package manager similar to pip. Conda quickly installs, runs and updates packages and their dependencies.
Check conda is installed and in your PATH if not install from conda$ conda -V
Check conda is up to dateconda update conda
To see a list of available python versions first, typeconda search "^python$"
and press enter.
Create a virtual environment for your projectconda create -n yourenvname python=x.x anaconda
Activate your virtual environment.# if you are using a UNIX operating sytem like ubuntusource activate yourenvname# if you are using windowsconda activate yourenvname
Install additional Python packages to a virtual environment. Failure to specify “-n yourenvname” will install the package to the root Python installation.conda install -n yourenvname [package]
Deactivate your virtual environment.conda deactivate
List all virtual envinmentconda env list
Delete a no longer needed virtual environmentconda remove -n yourenvname -all