Skip to content

Instantly share code, notes, and snippets.

@codez266
Forked from halfak/create_virtualenv.md
Created April 3, 2016 12:39
Show Gist options
  • Save codez266/4b9cb373468cd007d251912b9f252da7 to your computer and use it in GitHub Desktop.
Save codez266/4b9cb373468cd007d251912b9f252da7 to your computer and use it in GitHub Desktop.
Setting up a python 3.x Virtual Environment

Requires python-virtualenv: http://packages.ubuntu.com/trusty/python/python-virtualenv

Step 1: Create the virtualenv directory

In this sequence, I'm going to assume that python 3.4 is the installed verison.

$ cd ~
$ mkdir env
$ cd env
$ virtualenv -p $(which python3) 3.4 --system-site-packages
$ cd ~

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 ~/env/3.4/bin/activate
(3.4)$ 

Step 3: Do python 3 things

(3.4)$ python --version
Python 3.4.0
(3.4)$ pip --version
pip 7.1.0 from /home/halfak/env/3.4/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.

(3.4)$ deactivate
$ python --version
Python 2.7.6
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment