简体   繁体   English

使用 PyCharm 时出现 ModuleNotFoundError

[英]ModuleNotFoundError when using PyCharm

When running a script with this configuration in PyCharm:在 PyCharm 中使用此配置运行脚本时:

Pycharm 运行配置

I get我得到

/home/name/anaconda3/envs/butterfly/bin/python: Error while finding module specification for '/home/name/PycharmProjects/butterflydetector/butterflydetector/train.py' (ModuleNotFoundError: No module named '/home/name/PycharmProjects/butterflydetector/butterflydetector/train')

while it works when I run the following command from the terminal (same conda environment activated and at location ~/PycharmProjects/butterflydetector):当我从终端运行以下命令时它可以工作(相同的 conda 环境已激活且位于 ~/PycharmProjects/butterflydetector 位置):

python3 -m butterflydetector.train --arguments

What's the difference between the two ways of running this script and how can I fix this issue?运行此脚本的两种方式有什么区别,我该如何解决这个问题?

The solution is actually easy, what exactly the problem is I still can't say.该解决方案其实很简单,正是问题是我还不能说。 To just get it running clear the interpreter options line in the above image (or at least get rid of the -m ) and click on where it says 'Script path:'.要让它运行,请清除上图中的解释器选项行(或至少去掉-m )并单击它显示“脚本路径:”的位置。 Chose 'Module name:' instead and there you go.选择“模块名称:”,然后就可以了。 Also change the path to the script from the absolute path like it is in the above image to, in that specific case, butterflydetector.train .还要将脚本的路径从上图中的绝对路径更改为,在这种特定情况下, butterflydetector.train

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM