Python Virtual Environments

Conda and PIP

Imran Bangash
Nov 25, 2021

Packages list with versions saving using Pip

pip list # shows the packages

pip freeze > requirements.txt# save all packages

To create a virtual environment with the above packages

python3 -m venv myEnv
source myEnv/bin/activate
pip install -r requirements.txt

Packages list with versions saving using Conda

conda list # shows packages list

# save all packages either in txt or yaml file. yaml is better and commonly used

conda list -e requirements.txt

conda env export > myEnv.yml

To create a virtual environment with the above packages

conda create — name myEnv— file requirements.txt

or

conda env create -f myEnv.yml

--

--

Imran Bangash

Imran is a computer vision and AI enthusiast with a PhD in computer vision. Imran loves to share his experience with self-improvement and technology.