Skip to content

Instantly share code, notes, and snippets.

@AliZafar120
Last active January 17, 2021 16:24
Show Gist options
  • Save AliZafar120/181f0ab0ad88fa6d119189734c534522 to your computer and use it in GitHub Desktop.
Save AliZafar120/181f0ab0ad88fa6d119189734c534522 to your computer and use it in GitHub Desktop.
Python Virtual Environment

To install in linux :

pip install virtualenv

To create virtual environment (a folder will be created)

virtualenv <--name-->

Virtualenv -p /usr/bin/python2.6 <--name--> (if you want to use different version of python than default)

To activate virtual environment( from the root of created folder)

source <--name-->/bin/activate

<--name-->/Scripts/activate.bad (windows)

To check whether it is activated (will show the created folder path/bin/pip or /bin/python):

Which python

which pip

To see what packages are currently in Global/Virtual pip:

pip list

To install packages in virtual environment:

pip install <--packagename-->

To export current local package versions (will create file with version requirements of packages):

pip freeze --local > <--path_to_filename-->.txt

To exit virtual environment:

deactivate

To remove venv completely:

rm -rf <--path_to_venv_folder-->

To import from requirement file :

pip install -r <--filename.txt-->

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