开发者

why did virtualenv not include all of the system paths?

开发者 https://www.devze.com 2023-01-23 08:40 出处:网络
I created a virtualenv, and while it has many system paths, it doesn\'t have others. Specifically, pyshared and di开发者_运维百科st-packages don\'t seem to be included. As a result, my system-wide MyS

I created a virtualenv, and while it has many system paths, it doesn't have others. Specifically, pyshared and di开发者_运维百科st-packages don't seem to be included. As a result, my system-wide MySQLdb and psycopg2 aren't available. Any ideas why?


Seems to be related to Ubuntu's messing with python and virtualenv


The only possible way that i'm aware of, is if you have created your virtualenv with the argument --no-site-packages:

from Here:

If you build with virtualenv --no-site-packages ENV it will not inherit any packages from /usr/lib/python2.5/site-packages (or wherever your global site-packages directory is). This can be used if you don't have control over site-packages and don't want to depend on the packages there, or you just want more isolation from the global system.

so Here is an example to understand more:

First i will create a virtualenv normally (without --no-site-package) and you will see that i can always access django that is installed in my system site-packages (or dist-packages):

$ virtualenv A
New python executable in A/bin/python
Installing setuptools............done
$ source A/bin/activate
(A)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django  
>>> django.__file__
'/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'

But now i will create the virtual env using --no-site-package:

$ virtualenv B --no-site-package
New python executable in B/bin/python
Installing setuptools............done.
$ source B/bin/activate
(B)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django

now you see that virtaulenv was able to access django from system dist-packages (ubuntu) in my machine.

Hope this will help :)

0

精彩评论

暂无评论...
验证码 换一张
取 消