简体   繁体   English

python -m:查找模块规范时出错

[英]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.

相关问题 python -m导致“查找模块规范时出错” - python -m causes “Error while finding module specification for” 当我将 python3.7 降级到 python3.6 时,查找“virtualenvwrapper.hook_loader”的模块规范时出错 - Error while finding module specification for 'virtualenvwrapper.hook_loader' when I downgrade python3.7 to python3.6 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”) - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__') 查找“pyspark.worker”的模块规范时出错(ModuleNotFoundError:没有名为“pyspark”的模块) - Error while finding module specification for 'pyspark.worker' (ModuleNotFoundError: No module named 'pyspark') 如何修复 pip 错误“查找 'pip' 的模块规范时出错(AttributeError:模块 '__main__' 没有属性 '__file__')”? - How to fix pip error "Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')"? Google 应用引擎部署失败 - 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”) - Google app engine deployment fails- Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__') 问题 azure 测试聊天机器人“在查找“aiohttp.web”的模块规范时出错(ModuleNotFoundError:没有名为“aiohttp”的模块) - Issue azure test chat bot " Error while finding module specification for 'aiohttp.web' (ModuleNotFoundError: No module named 'aiohttp') numpy 已经安装在我的笔记本电脑中,但是当我导入 numpy 模块时,python 出现错误 - numpy is already installed in my laptop,but python gives error while i'm importing numpy module 查找最大数字时出现Python错误 - Python error while finding greatest number 在 selenium python webdriver 中查找元素时出错 - Error while finding element in selenium python webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM