A virtual environment in python is like a tool that helps to manage python packages and third-party libraries. Anaconda is the world's favorite package management tool that helps to create a python version-specific virtual environment. It automates the third-party package/libraries installation process by checking compatibility and resolving dependencies with another package.
In this tutorial, I will show you how to create a virtual environment in Anaconda. Let’s start-
# Checking python version
python --version
# Checking conda version
conda -V
# Using cd command navigate to the folder where you want to create a virtual environment
cd < Name of Your Directory/Folder >
For this tutorial, we create a virtual environment name python_demo_env for python version 3.8.
# conda create -n < Name of the Virtual Environment > python=x.x anaconda
conda create -n python_demo_env python=3.8 anaconda
You have just created a python3 virtual environment.
# conda activate < Name of the Virtual Environment >
conda activate python_demo_env
Now, you can install any Python package inside this virtual environment. We can use the pip or conda command to install packages. Let’s install Django, the most popular python framework, inside our python_demo_env.
# Install Django using conda command
conda install -c anaconda django
# Install Django using pip command
pip install django
You can also specify the package version during the installation. For example, pip install django==3.2.7
conda deactivate
#conda remove -n envname package_name
conda remove -n python_demo_env django
It will remove the Django package from our virtual environment.
Share To
A passionate geospatial developer and analyst whose core interest is developing geospatial products/services to support the decision-making process in climate change and disaster risk reduction, spatial planning process, natural resources management, and land management sectors. I love learning and working with open source technologies like Python, Django, LeafletJS, PostGIS, GeoServer, and Google Earth Engine.