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.
What’s a Virtual Environment?
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.
How to Create a Virtual Environment with Conda
Check conda is installed and in your PATH if not install from conda
$ conda -V
Check conda is up to date
conda update conda
To see a list of available python versions first, type
conda search "^python$"
and press enter.
Create a virtual environment for your project
conda create -n yourenvname python=x.x anaconda
Activate your virtual environment.
# if you are using a UNIX operating sytem like ubuntu source activate yourenvname # if you are using windows conda 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.
List all virtual envinment
conda env list
Delete a no longer needed virtual environment
conda remove -n yourenvname -all
You might also like:-
- How To Set Up Jupyter Notebook with Python 3 on Ubuntu 20.04
- Connecting Rasa to a website - A step by step tutorial