pip installing in global site-packages instead of virtualenv
Funny you brought this up, I just had the exact same problem. I solved it eventually, but I'm still unsure as to what caused it.
Try checking your bin/pip
and bin/activate
scripts. In bin/pip
, look at the shebang. Is it correct? If not, correct it. Then on line ~42
in your bin/activate
, check to see if your virtualenv path is right. It'll look something like this
VIRTUAL_ENV="/Users/me/path/to/virtual/environment"
If it's wrong, correct it, deactivate
, then . bin/activate
, and if our mutual problem had the same cause, it should work. If it still doesn't, you're on the right track, anyway. I went through the same problem solving routine as you did, which pip
ing over and over, following the stack trace, etc.
Make absolutely sure that
/Users/kristof/VirtualEnvs/testpy3/bin/pip3
is what you want, and not referring to another similarly-named test project (I had that problem, and have no idea how it started. My suspicion is running multiple virtualenvs at the same time).
If none of this works, a temporary solution may be to, as Joe Holloway said,
Just run the virtualenv's pip with its full path (i.e. don't rely on searching the executable path) and you don't even need to activate the environment. It will do the right thing.
Perhaps not ideal, but it ought to work in a pinch.
Link to my original question:
VirtualEnv/Pip trying to install packages globally
Including global package into a virtualenv that has been created with --no-site-packages
If you're using virtualenvwrapper and you might be able to use the postmkvirtualenv script to automatically create symlinks in the new virtualenv sitepackages directory.
#!/bin/sh
cdsitepackages
ln -s /path/to/system/site-packages/package-name
cdvirtualenv
Why i already have installed modules in my virtualenv?
TL;DR: The django-admin
and cookiecutter
commands are accessible from your virtual environment because they are on PATH. This isn't related to the Python virtual environment, but rather due to your whole system. If you want to make global packages accessible in your virtual environment, see this answer.
django-admin
and cookiecutter
are executables. They're located in some folder on your system (most likely the Scripts folder of your Python installation), and that folder is in PATH. Therefore, the shell can access them, no matter if you are in a virtual environment.
To contrast with that, numpy
and pandas
are only libraries. Therefore, when you try to import them in your code which is run in the virtual environment, they cannot be accessed. This can be changed by either installing them in the virtual environment, or including system site packages, which you can see how to do in this answer.
If you tried to import django
or cookiecutter
, that wouldn't work either (in your virtual environment), just like numpy
or pandas
. There's no way to "fix this", because it isn't broken. I wouldn't suggest removing Scripts from PATH, because that would mean those commands would never be accessible.
Related Topics
How to Avoid Explicit 'Self' in Python
Cannot Concatenate 'Str' and 'Float' Objects
How to Implement Server Push in Flask Framework
Get Lat/Long Given Current Point, Distance and Bearing
How to Switch to the Active Tab in Selenium
Why Do I Get Typeerror: Can't Multiply Sequence by Non-Int of Type 'Float'
How to Compare String and Integer in Python
Plotting a Decision Boundary Separating 2 Classes Using Matplotlib's Pyplot
Append to a List Defined in a Tuple - Is It a Bug
Reading Unicode File Data with Bom Chars in Python
Cannot Install Lxml on MAC Os X 10.9
Pip Installing in Global Site-Packages Instead of Virtualenv
Redirecting Stdout and Stderr to a Pyqt4 Qtextedit from a Secondary Thread
Keyerror: 'Tcl_Library' When I Use Cx_Freeze
Python JSON Parser Allow Duplicate Keys
How to Do Multiple Arguments to Map Function Where One Remains the Same