2
$ 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

来自以下 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 与 loader.py 位于同一目录中。它适用于我的开发盒,我做了一个 svn 导出到登台,并且发生了上述情况。任何指针?

我能解决的唯一实质性区别是这次我用完了 virtualenv。

编辑:我将命令行更改为:

$ bin/python src/app/utils/loader.py utils.newTasks checkForStuff 

并且发现模块没问题。但我的下一个命令是调用其中一个模块函数checkForStuff

parser.add_argument('func',metavar='function', help="the target function name")
...
func_param = getattr(module,args.func)

现在它找不到功能了?

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'

如果我进入 bin/python:

>>> import utils.newTasks as nt
>>> nt.checkForStuff
<function checkForStuff at 0x29b2f50>

这很烦人!

4

1 回答 1

1

bin/python不是您登台机器上的 python 二进制文件。检查它是否像普通 python 那样将脚本目录插入到 sys.path 中。

于 2012-11-23T00:28:38.843 回答