Skip to content

Instantly share code, notes, and snippets.

@adamwight
Forked from halfak/create_virtualenv.md
Last active November 15, 2017 15:04
Show Gist options
  • Save adamwight/a82d428538bd3c4b1fe5c3345700ec1e to your computer and use it in GitHub Desktop.
Save adamwight/a82d428538bd3c4b1fe5c3345700ec1e to your computer and use it in GitHub Desktop.
Setting up a python 3.x Virtual Environment

Step 0: Set up python virtualenv

virtualenv is a command-line utiltity that will allow you to encapsulate a python environment. Ubuntu calls the package that installs this utility "python-virtualenv". You can install it with $ sudo apt-get install python-virtualenv.

Step 1: Create the virtualenv directory

$ cd ~
$ mkdir venv
$ virtualenv -p python3 --system-site-packages ~/venv

Step 2: Activate the virtualenv

You'll need to 'activate' the virtualenv in order to make use of it. It will re-write your prompt to put the name of the virtualenv at the beginning.

$ source ~/venv/bin/activate
(venv)$ 

Step 3: Do python 3 things

(venv)$ python --version
Python 3.4.0
(venv)$ pip --version
pip 7.1.0 from /home/halfak/venv/lib/python3.4/site-packages (python 3.4)

Step 4: Deactivate the virtualenv

When you want to go back to the default python state, you'll need to deactivate the environment.

(venv)$ deactivate
$ python --version
Python 2.7.6
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
@adamwight
Copy link
Author

@halfak I've simplified a bit, you might want to pull this revision over to your gist.

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