[英]Python ImportError
$ bin/python src/app/utils/loader.py newTasks checkForStuff
Traceback (most recent call last):
File "bin/python", line 135, in <module>
execfile(__file__)
File "src/app/utils/loader.py", line 154, in <module>
module = __import__(args.module)
ImportError: No module named newTasks
from the following loader.py: 来自以下的loader.py:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Runs python')
parser.add_argument('module', metavar='module', help="the target module")
args = parser.parse_args()
module = __import__(args.module)
newTasks.py is in the same directory as loader.py. newTasks.py与loader.py位于同一目录中。 It works on my dev box, I did an svn export to staging and the above happened.
它可以在我的开发箱上工作,我将svn导出到暂存中,并且发生了上述情况。 Any pointers?
有指针吗?
Only material difference I can work out is this time I'm running out of virtualenv. 我可以解决的唯一实质区别是这次我用尽了virtualenv。
EDIT: I changed the command line to: 编辑:我将命令行更改为:
$ bin/python src/app/utils/loader.py utils.newTasks checkForStuff
and the module was found ok. 并发现模块正常。 But my next command is to call one of the module functions
checkForStuff
: 但是我的下一条命令是调用模块功能之一
checkForStuff
:
parser.add_argument('func',metavar='function', help="the target function name")
...
func_param = getattr(module,args.func)
and now it cannot find the function? 现在找不到功能了吗?
Traceback (most recent call last):
File "bin/python", line 135, in <module>
execfile(__file__)
File "src/app/utils/loader.py", line 156, in <module>
func_param = getattr(module,args.func)
AttributeError: 'module' object has no attribute 'checkForStuff'
If I go into bin/python: 如果我进入bin / python:
>>> import utils.newTasks as nt
>>> nt.checkForStuff
<function checkForStuff at 0x29b2f50>
This is annoying! 真烦人!
bin/python
is not the python binary on your staging machine. bin/python
不是登台计算机上的python二进制文件。 Check whether it inserts the scripts directory into sys.path as ordinary python does. 检查它是否像普通python一样将脚本目录插入sys.path中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.