How to create a virtualenv with Python3.3 in Ubuntu?

Python 3.3 has venv built-in.

http://docs.python.org/3/library/venv.html#module-venv

Simply run

pyvenv-3.3 /path/to/environment

And then to activate it

source /path/to/environment/bin/activate

This built-in version of virtualenv is much more flexible than what you're probably used to. For example, you can extend EnvBuilder to do pretty much whatever you want. You can copy an example implementation of EnvBuilder from the link below and play around with it: http://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder

That script above likely does most of what we expect to get out of virtualenv. So if you just need a virtualenv with easy_install and pip, you should be good to go.

See @MarkOfSine's edits below for clarification on how to get running if you're still confused.


To add to the above, and as per docs:
For example, after executing: pyvenv-3.3 /path/to/my_project/venv
You can run distribute_setup.py, which seems to do various things, but essentially you end up with easy_install in your ./my_project/venv/bin directory.
This can then be used to install pip and the like.

It does not say where you should get distribute_setup.py from, so I downloaded from:

http://python-distribute.org/distribute_setup.py

and using the activated environment:

cd /path/to/my_project
source venv/bin/activate

ran :

python distribute_setup.py

and

easy_install pip

Which then completed the setup of the virtual environment more inline with virtualenv on python 2.x


It is easier than as it seems:

virtualenv -p /usr/bin/python3 yourenv
source yourenv/bin/activate
pip install package-name

really works :)


  1. Take backup of site-packages.

    cp -r /usr/local/lib/python2.7/site-packages/ /tmp/site-packages

  2. Truncate that directory

    rm -rf /usr/local/lib/python2.7/site-packages/

  3. Now try the same

    virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3

  4. To install without pip

    virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3 --no-pip

EDIT: Looks like the version of virtualenv (1.7.1.2) and python3.3 are not compatible. So, please try this

  1. Uninstall python-virtualenv using sudo apt-get remove python-virtualenv

  2. wget http://peak.telecommunity.com/dist/ez_setup.py; sudo python ez_setup.py This will install latest easy_install.

  3. sudo easy_install pip

  4. sudo pip install virtualenv

  5. virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3

Tags:

Python

Python3