简体   繁体   English

Python模块名称别名?

[英]Python module name aliases?

I've got a module called 'cloud.aws.boto'. 我有一个名为“ cloud.aws.boto”的模块。 I need this to import the boto library I installed into my virtualenv. 我需要将导入的boto库导入到virtualenv中。

If I add import boto.ec2 to my 'cloud.aws.boto.py' file, python complains because it's trying to import 'ec2' from the local file instead of the library in my virtualenv. 如果我将import boto.ec2添加到我的“ cloud.aws.boto.py”文件中,python会抱怨,因为它试图从本地文件而不是我的virtualenv中的库导入“ ec2”。

How can I import another module with the same name as the one I'm importing from? 如何导入与我要导入的模块同名的另一个模块?

http://docs.python.org/2/tutorial/modules.html http://docs.python.org/2/tutorial/modules.html

You can try to remove "." 您可以尝试删除"." from sys.path just before this import (but don't forget to prepend it back once you are done, otherwise you won't be able to imnport your other local modules). 在导入之前从sys.path (但是一旦完成,别忘了将其添加回去,否则您将无法导入其他本地模块)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM