I'm starting to use virtualenv and virtualenvwrapper on my projects.
After activating the virtualenv with the workon
command, i installed the following packages with pip install -U <package>
:
$ lssitepackages
django pip
Django-1.3-py2.7.egg-info pip-1.0.1-py2.7.egg-info
easy-install.pth setuptools-0.6c11-py2.7.egg
fabric setuptools.pth
Fabric-1.0.1-py2.7.egg-info south
geopy South-0.7.3-py2.7.egg-info
geopy-0.94.1-py2.7.egg-info
The problem here is (running commands with the virtualenv activated):
$ whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.7 /etc/python2.6 /etc/python /etc/python2.7 /usr/lib/python2.6 /usr/lib/python2.7 /usr/lib64/python2.6 /usr/lib64/python2.7 /usr/local/lib/python2.6 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
$ whereis django-admin
django-admin: /usr/bin/django-admin /usr/local/bin/django-admin.py /usr/share/man/man1/django-admin.1.gz
$ whereis fab
fab: /usr/local/bin/fab
My virtualenv it's not using the local packages!
How do I force the virtualenv use local Python and local version of packges instead my machine packages?
Update - Possible solution
I created a new virtualenv with mkvirtualenv --no-site-packages <name>
and now I got these outputs:
$ which python
/home/user/.virtualenvs/VIRTUALENVNAME/bin/python
$ which django-admin
/usr/bin/django-admin
$ which django-admin.py
/home/user/.virtualenvs/VIRTUALENVNAME/bin/django-admin.py
$ which fab
/home/user/.virtualenvs/VIRTUALENVNAME/bin/fab
Sounds like it's working now... except for the "django-admin" command.
try install the virtualenv using:
mkvirtualenv --no-site-packages
to create the virtualenv without any external python libraries
You're using two different commands to locate which Python version is being used. The first time, you used "whereis" and the second time you used "which". "whereis" is not the command you want to use to identify which version will run in your environment.
From the man pages of "whereis":
whereis locates source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form.ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in a list of standard Linux places.
This last line is important, here. whereis "attempts to locate the desired program in a list of standard Linux places." When you're using a virtualenv, that version of Python is not in a standard Linux place.
Use "which" instead, like you did the second time. Excerpt from the man pages of "which":
which returns the pathnames of the files (or links) which would be exe‐ cuted in the current environment,
That's the one you want to use to identify which version of Python will run in your virtualenv.
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.