Total Pageviews

Thursday, 24 June 2021

Pipenv vs virtualenv vs conda environment

 

Python has three popular ways of creating virtual environment at the moment. In this post I want to talk about how to use each.

Virtual Environment

Virtualenv was the default way of creating virtual environment for many years. It is still used by many although people are moving to improved pipenv or conda (explained below).

cd /path/to/downloadsfolder
python get-pip.py
pip install virtualenv
virtualenv venv
venv\Scripts\activate
pip freeze > requirements.txt
pip install -f requirements.txt

PipEnv

Pipenv was created due to many shortcomings of virtualenv such as it not making a distinction if project dependency and the dependies of the project dependency, not having mechanism to distinguish dev and production needs etc.

pip install pipenv
pipenv install 
pipenv shell 
pip install <package> --dev

Conda Environment

If you are an engineer, or a scientist or use Numpy/Scipy package in windows environment, you have probably experienced the frustration of having to do a lot of work to install numpy/scipy packages. Anaconda is a distribution of python that makes it super simple to install those packages. Anaconda also has their own virtual environment system called conda. Make sure to have Anaconda installed.

conda create --name environment_name python=3.6
conda env export > environment.yml
conda env create -f environment.yml

No comments:

Post a Comment