Skip to content

Instantly share code, notes, and snippets.

@hanvari
Last active February 27, 2022 06:06
Show Gist options
  • Save hanvari/43fec18cd5a98b78a65af5b4449f9eb7 to your computer and use it in GitHub Desktop.
Save hanvari/43fec18cd5a98b78a65af5b4449f9eb7 to your computer and use it in GitHub Desktop.
Python Virtual Environments

Python Virtual Environments

Using virtualenv

$ pip install virtualenv
$ virtualenv --version
# Creating env
$ virtualenv [--no-site-packages] [--python=/usr/bin/python2.7] env-name  
$ lsvirtualenv
# activate env
$ source env-name/bin/activate
# install any desired packages here specific for the current virtual-env
$ pip install some-package
# installing from a list of packages
$ pip install -r requirements.txt
# creating a list of currently installed packages
$ pip freeze > requirements.txt
# Deactivate env
$ deactivate
# to delete env, simply delete the folder

Using conda

# create env
$ conda create --name my-env [python=3.6]
# list environments
$ conda info --envs
# activate
$ source activate my-env
# install anay packages here if needed
# deactivate
$ source deactivate
# remove env
$ conda remove --name my-env

Ref: https://www.freecodecamp.org/news/python-virtual-environments-explained-with-examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment