PyCharm error: 'No Module' when trying to import own module (python script)

前端 未结 14 1832
醉话见心
醉话见心 2020-12-07 07:57

I have written a module (a file my_mod.py file residing in the folder my_module). Currently, I am working in the file cool_script.py t

14条回答
  •  时光说笑
    2020-12-07 08:13

    PyCharm Community/Professional 2018.2.1

    I was having this problem just now and I was able to solve it in sort of a similar way that @Beatriz Fonseca and @Julie pointed out.

    If you go to File -> Settings -> Project: YourProjectName -> Project Structure, you'll have a directory layout of the project you're currently working in. You'll have to go through your directories and label them as being either the Source directory for all your Source files, or as a Resource folder for files that are strictly for importing.

    You'll also want to make sure that you place __init__.py files within your resource directories, or really anywhere that you want to import from, and it'll work perfectly fine.

    I hope this answer helps someone, and hopefully JetBrains will fix this annoying bug.

提交回复
热议问题