Python – Creating a Virtual Environment for Python2 or Python3

1. Install virtualenv.

pip install virtualenv

2. cd into your project directory.

cd project/

3. Create virtual environment. This will create venv directory under your project.

virtualenv venv --python=python2.7

4. Activate virtualenv

source venv/bin/activate

Done. Install whatever package you need for your project using

pip install

More…

If you are creating a virtual environment for python3, and you have python3 at the system level, simply replace step 3 with

virtualenv venv

If you want to remove virtual environment, first deactivate it by running

deactivate

and remove the venv directory.

rm -rf venv
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 )

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