简体   繁体   中英

Python3 pip installing globally when in a virtualenv

Attempting to finally make the jump to Python 3, but am running into some issues with virtualenvwrapper. I start out by creating the virtual environment like so:

mkvirtualenv -p /usr/local/bin/python3 projectname

which yields:

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3'
New python executable in projectname/bin/python3.3
Also creating executable in projectname/bin/python
Installing setuptools, pip...done.

So far, so good. I check the python console to make sure that the environment is looking at the correct interpreter and all that and it is. Here's where sadness happens (while the virtualenv is active):

pip install flask claims to be successful, but alas:

Python 3.3.3 (default, Jan  2 2014, 13:26:32) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'flask'

Here's the issue:

$ pip show flask
---
Name: Flask
Version: 0.10.1
Location: /usr/local/lib/python3.3/site-packages
Requires: Werkzeug, Jinja2, itsdangerous

Unless I'm completely misunderstanding virtualenv/wrapper and their respective magics (which I very well could be), it seems like pip install is installing Flask globally rather than to the site-packages within my virtualenv, and thus the virtualenv is ignoring it.

Any clues what's going on here/how to fix? Am I wrong in assuming that virtualenvwrapper is ready for primetime with python3? Pretty solutions where I don't have to mangle my .bashrc or manually set environment variables are preferable. I'm hoping there's a way to do this through the api's provided by virtualenv and virtualenvwrapper.

Thanks!

I had problems with pip installing packages globally instead of in the activated virtualenv too. Have a look at pip installing in global site-packages instead of virtualenv for the question (and the answer).

Basically, the solution consisted of modifying the shebang of the pip scripts within the virtualenv as they pointed to the wrong python installation (global instead of in the virtualenv). Just change the shebang to point to the correct location and you're set.

Note: credit should go to Chase Ries who came up with the solution.

I had the same issue. It appears to be resolved as of Virtualenv 1.11.4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM