简体   繁体   中英

ModuleNotFoundError when using PyCharm

When running a script with this configuration in 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):

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:'. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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