[英]python -m: Error while finding module specification
According to the python doc the -m
flag should do the following:根据python doc -m
标志应该执行以下操作:
Search sys.path for the named module and execute its contents as the
__main__
module.在 sys.path 中搜索命名模块并将其内容作为__main__
模块执行。
When I run my script simply with the python
command, everything works fine.当我简单地使用python
命令运行我的脚本时,一切正常。 Since I now want to import something from a higher level, I have to run the script with python -m
.由于我现在想从更高级别导入某些内容,因此我必须使用python -m
运行脚本。 However the __name__ == "__main__"
statement seems to return False
and the following Error is produced:然而__name__ == "__main__"
语句似乎返回False
并产生以下错误:
/home/<name>/anaconda3/bin/python: Error while finding module specification for 'data.generate_dummies.py' (AttributeError: module 'data.generate_dummies' has no attribute '__path__')
I dont't understand what the __path__
attribute has to do with that.我不明白__path__
属性与此有什么关系。
The error you get occurs when python tries to look for a package/module that does not exist.当 python 尝试查找不存在的包/模块时,会发生错误。 As user2357112 mentions , data.generate_dummies.py
is treated as a fully specified module path (that does not exist), and an attempt is made to import a submodule py
(that is also non-existent).正如user2357112 提到的, data.generate_dummies.py
被视为完全指定的模块路径(不存在),并尝试导入子模块py
(也不存在)。
Invoke your file without .py
, if you're using the -m
flag, like this:如果您使用的是-m
标志,则调用不带.py
的文件,如下所示:
python -m data.generate_dummies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.