gpt4 book ai didi

Python 导入错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:19 27 4
gpt4 key购买 nike

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

这很烦人!

最佳答案

bin/python 不是您暂存计算机上的 python 二进制文件。检查它是否像普通python一样将脚本目录插入到sys.path中。

关于Python 导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13521647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com