Python virtualenv How To

To install the virtualenv command, run:

pip install virtualenv

If that fails and you have root priviledges, run:

sudo pip install virtualenv

To create a python virtualenv called venv, run:

virtualenv venv

To activate that environment, run:

source venv/bin/activate

You can then install whatever you want in this environment (using pip install) without affecting the system python. To recreate an environment from saved requirements, run:

pip install -r requirements.txt

To save the requirements (which allows you or someone else to recreate the environment, as shown above), run:

pip freeze > requirements.txt

To stop using the current environment, run:

deactivate

To delete a virtual environment called venv, run:

rm -r venv

For more information, see The Hitchhiker’s Guide to Python: Virtual Environments

Advertisements

About jimbelton

I'm a software developer, and a writer of both fiction and non-fiction, and I blog about movies, books, and philosophy. My interest in religious philosophy and the search for the truth inspires much of my writing.
This entry was posted in programming and tagged , , , , . Bookmark the permalink.

Leave a Comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s