Nils Guillermin Nils Guillermin - 1 year ago 105
Python Question

Pip default behavior conflicts with virtualenv?

I was following this tutorial

When I got to

virtualenv flask
command, I received this error message:

Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

This makes sense as the point of virtualenv is to create a new environment which you can control, and the
command places everything in a specific location, defeating the objective of separation of dev environment.

It seems like pip defaults to
installations though, can I change this default behavior? And, even better, can I get pip to play nice with virtualenv at all times?

To clarify, here is what my terminal looks like.

MELCHIOR:miguelgrinberg-microblog megablanc$ virtualenv flask
New python executable in flask/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/Users/megablanc/Library/Python/2.7/bin/virtualenv", line 11, in <module>
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/", line 832, in main
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/", line 1004, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/", line 969, in install_wheel
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/", line 910, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1

Answer Source

You don't need to set the --user flag. After you create your virtualenv (virtualenv flask), activate it: source flask/bin/activate. Your shell should look something like (flask) ~>.

Once your virtualenv is activated, you should be able to pip install packages without issue. For example, pip install numpy. They'll be installed in: lib/python2.6/site-packages/ (for whatever version of Python you are using)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download