Reputation: 9046
I create and activate a virtualenv (venv) using Python 3.3's built-in way of doing it:
$ python3.3 -m venv env
$ source env/bin/activate
At this point python
is the python in my virtualenv, which I expect:
(env) $ which python
/my_home_directory/env/bin/python
Now I want to install distribute and pip, so I download the setup scripts and run them:
(env)$ wget http://python-distribute.org/distribute_setup.py
(env)$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
(env)$ python distribute_setup.py
(env)$ python get-pip.py
These commands complete successfully. At this point I inspect my venv to find another directory called "local" which wasn't there before. env/local/bin contains my easy_install and pip executables, and they're still aliased to my system's existing easy_install and pip:
(env)$ ls env
bin include lib local pyvenv.cfg
(env)$ ls env/bin
activate pydoc python python3 python3.3
(env)$ ls env/local/bin
easy_install easy_install-3.3 pip pip-3.3
(env)$ which easy_install
/usr/bin/easy_install
(env)$ which pip
/usr/bin/pip
I believe this is a departure from Python 2.x's behavior. At this point I expect easy_install
and pip
to be using the virtualenv's copies, and using them to install eggs will put them in the virtualenv.
Going a bit further, I crack open env/bin/activate to find that env/bin is prepended to the system path, but env/local/bin is not. That explains the behavior I'm seeing. I can work around this problem by editing env/bin/activate to add the env/local/bin directory to the path, something like:
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
PATH="$VIRTUAL_ENV/local/bin:$PATH" # my new line
export PATH
So, what's going on here? Is this a bug, or am I missing something?
I'm on Ubuntu 12.10 in case that makes a difference.
Upvotes: 25
Views: 2864
Reputation: 16345
I have a feeling there's a bug in Ubuntu's python packages or distribute somewhere… but I haven't tracked it down (and I'm not sure I care to).
For whatever reason, the VIRTUAL_ENV environment variable needs to be set the root of the virtualenv for distribute and pip to install properly.
This gist, adopted from Vinay Sajip's code sample in the Python 3 docs, sets said variable; both distribute and pip will install properly when using it.
Upvotes: 2
Reputation: 6368
It's in the python docs.
'/usr/local' is the default exec_prefix. Read the venv docs for detail how to change the default behaviour. There's even an example there that shows how to make a venv.EnvBuilder
that installs distribute and pip for you.
if you find distribute docs, please let me know ;-)
Upvotes: 1
Reputation: 4984
I had the same problem.
In activate
script file I need to add as first line (of cource after #!...
):
unset PYTHON_PATH
Upvotes: 0