2

I create a new virtual env but pip is always the "global" one

$ python3 -m venv MyVenv
$ source Myvenv/bin/activate
(MyVenv)$ which pip
/usr/local/bin/pip

and I don't know why.

I want to use the env's one... (I'm on Ubuntu 15.04)

edit: full $PATH of a test venv as required:

/home/doc/test/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

3 Answers 3

0

No repro.

$ python3 -m venv MyVenv
$ source MyVenv/bin/activate

(MyVenv) $ which pip
/home/oli/Desktop/MyVenv/bin/pip

(MyVenv) $ which pip3
/home/oli/Desktop/MyVenv/bin/pip3

I'd try again (honestly, those were the commands I used) but failing that, with most virtualenv-related things, if you call the binary directly, it'll use the right environment even without activating it.

In my case that looks like:

/home/oli/Desktop/MyVenv/bin/pip3 install Django

There is also a bug in ensurepip in Python 3 on 14.04 (and maybe newer versions) in that it's completely missing. You can manually install it. If you're hitting this, it might explain what you're seeing.

wget -qO- http://d.pr/f/YqS5+ \
| sudo tar xzf - -C $(python3 -c "import sys; print(sys.path[1])") --no-same-owner

Then recreate and reactivate your venv.

10
  • I tried the same thing on my vps (ubuntu 14.04), pip is always the global one...
    – Doc
    Jun 10, 2015 at 8:31
  • I don't know what to tell you. Is activate crashing out for some reason? Is your local bin in the $PATH? (run echo $PATH)
    – Oli
    Jun 10, 2015 at 8:49
  • yes, local bin is in the venv $PATH, along with the venv's bin
    – Doc
    Jun 10, 2015 at 9:42
  • Can you append the full output of echo $PATH to your question, please?
    – Oli
    Jun 10, 2015 at 10:29
  • @Doc you can use python -mpip, to make sure that pip corresponds to python executable (virtualenv or not). Run python3 -m ensurepip, to make sure pip is available.
    – jfs
    Jun 10, 2015 at 12:15
0

fixed by reinstalling ubuntu, i think i had screwed up python3 installation with some "apt-get" packages

0

In my case, after creating the virtual environment via

python -m venv test1

I moved the entire venv directory and then activated it. Turns out moving the venv folder seems to break the venv's pip path. I was able to reproduce by creating a new one and moving it again.

With the venv activated, if you run

set | grep test1

you can see the venv bin directory is added to the path.

So one solution is just create the venv exactly where you want it and don't move it. Or else modify the venv's activate shell script to change the VIRTUAL_ENV value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.