Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 --user command places everything in a specific location, defeating the objective of separation of dev environment.

It seems like pip defaults to --user 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>
    sys.exit(main())
  File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 832, in main
    symlink=options.symlink)
  File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 1004, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 969, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", 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
like image 701
Nils Guillermin Avatar asked Jun 02 '15 19:06

Nils Guillermin


2 Answers

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)

like image 94
benlaird Avatar answered Oct 08 '22 18:10

benlaird


what worked for me was to change the $VIRTUAL_ENV_DIRECTORY/pyvenv.cfg to include-system-site-packages = true seems hacky though.

like image 28
Fabian Bosler Avatar answered Oct 08 '22 18:10

Fabian Bosler