从Python虚拟环境导入模块(SQLITE3)
我使用的是安装了 python、django 和 pinax 的 Windows 计算机。
我可以从任何正常位置导入模块(即使它不在实际安装的目录中)。但是,当我处于为 Pinax 构建的虚拟环境中时,我无法导入这些相同的模块。
造成这种情况的可能原因有哪些?可能的解决方案有哪些?
I am using a Windows machine with python, django, and pinax installed.
I can import modules from any normal location (even if it's not in the actuall installed directory). However, I cannot import these same modules when I am in a virtual environment that I built for Pinax.
What are possible causes of this? What are possible solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要诊断导入失败,请尝试使用 python 的 -v 开关:
它将显示导入模块的尝试。
To diagnose failure to import, try using the -v switch to python:
It will show its attempts to import your modules.
正如摘要所说,
然而,您似乎对您构建的 virtualenv“不共享库”感到惊讶......当不共享是 virtualenv 的全部要点时,您为什么感到惊讶?!-)
一旦您已经制作了一个 python virtualenv.py ENV,以继续引用我已经指出的摘要,“如果您使用 ENV/bin/easy_install,则软件包将被安装到环境中”。
因此,执行此操作以安装可在虚拟环境中导入的所有软件包。
(假设您已使用
--no-site-packages
选项来创建虚拟环境,则还需要对“站点范围”安装的所有软件包执行此操作,因为该选项是将它们排除在外,以实现更好的控制和隔离)。As the summary says,
Yet you appear surprised that the virtualenv you've built "doesn't share libraries"... why are you surprised, when that not-sharing is the whole point of virtualenv?!-)
Once you've made a
python virtualenv.py ENV
, to keep quoting from the summary I've already pointed you to, "if you use ENV/bin/easy_install the packages will be installed into the environment".So, do that to install all packages you need to be available for importing in the virtual environment.
(Assuming you've used the
--no-site-packages
option to make the virtual environment, you need to do that also for all packages you had installed "site-wide", since the purpose of that option is to exclude them for better control and isolation).