Python virtualenv tutorial

Virtualenv is a tool to isolate projects packages installations.

Installation

pip install virtualenv

Check installation

virtualenv --version

Create virtualenv

cd my_project_folder
virtualenv my_project

Create virtualenv with specific python version

virtualenv -p /usr/bin/python2.7 my_project

Activate virtualenv

source my_project/bin/activate

Deactivate

deactivate

Create requirements.txt

pip freeze > requirements.txt

Install from requirements.txt

pip install -r requirements.txt

 

virtualenvwrapper

Virtualenvwrapper helps to manage virtual environments in one place.

Install virtualenvwrapper

pip install virtualenvwrapper
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh

Full instruction https://virtualenvwrapper.readthedocs.io/en/latest/install.html

Create venv

mkvirtualenv my_project

Activate venv

workon my_project

Deactivate venv

deactivate

Remove venv

rmvirtualenv venv

List of venvs

lsvirtualenv

Navigate to venv directory

cdvirtualenv

Navigate to site-packages

cdsitepackages

ls of site-packeges

lssitepackages

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s