[英]Append single package folder to sys.path
I use a script under virtualenv, that requires bzrlib package which is not available in my virtualenv but is included in my system python packages: /usr/lib/python2.7/dist-packages/bzrlib/
我在virtualenv下使用一个脚本,该脚本需要bzrlib软件包,该软件包在我的virtualenv中不可用,但包含在我的系统python软件包中: /usr/lib/python2.7/dist-packages/bzrlib/
If I want to use it, one option is to extend sys.path, but I would have to include the parent folder /usr/lib/python2.7/dist-packages/
which contains many other packages, that I don't want to make available. 如果要使用它,一个选项是扩展sys.path,但是我必须包括父文件夹/usr/lib/python2.7/dist-packages/
,其中包含许多其他我不想要的软件包提供。 Is there any easy way to include just bzrlib
package? 有什么简单的方法可以只包含bzrlib
软件包?
What about creating a link in different directory and importing using that? 如何在其他目录中创建链接并使用该链接导入呢? Or even in your own project. 甚至在您自己的项目中。
ln -s /package/dir/path /project/dir/path
If you have to load it remotely, here is the link provided by @unutbu showing how to do it: 如果您必须远程加载它,这是@unutbu提供的链接,其中显示了如何执行此操作:
How to import a module given the full path? 给定完整路径,如何导入模块?
import imp
foo = imp.load_source('module.name', '/path/to/file.py')
foo.MyClass()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.