开发者

virtualenv does not copy standard modules like shutil and urllib2

开发者 https://www.devze.com 2022-12-24 19:47 出处:网络
When I create a new virtualenv, virtualenv .virtualenvs/my_env, there is only a subset of the standard python modules copied/linked to the new virtualenv.

When I create a new virtualenv, virtualenv .virtualenvs/my_env, there is only a subset of the standard python modules copied/linked to the new virtualenv.

For example, when I do ls -l in .virtualenvs/my_env/lib/python2.6, I see:

...
... os.py -> /usr/lib/python2.6/os.py
... os.pyc -> /usr/lib/python2.6/os.pyc

but modules like shutil and urllib2 are not copied even if they are in /usr/lib/python2.6/shutil.py. I am using Ubuntu 9.开发者_如何学JAVA10.

Is this the expected behavior? How can I install modules such as shutil in a virtualenv (I could not find these modules on pypi)?


virtualenv munges sys.path to insert your virtual environment in front of the system libraries, but the system libraries are still on the path, so they should still be accessible.

So, for instance, do:

>>> import os
>>> os
<module 'posixpath' from '/environments/userpython/lib/python2.6/posixpath.pyc'>
>>> import shutil
>>> shutil
<module 'shutil' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/shutil.pyc'>

My os module is from my virtual environment, but the shutil module is coming from my system Python.

0

精彩评论

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