0

I am using MacOS with Pycharm. My directory structure:

enter image description here

Inside test2_main.py, I run

from test1 import x

ModuleNotFoundError error

from test1 import x
ModuleNotFoundError: No module named 'test1'

How can I solve it if I want to use the same import code?

Tung
  • 33
  • 3

1 Answers1

0

Go to Run->Edit Configurations and in the menu of your Run Configuration there is a field called Working directory.

Scorpio
  • 1,124
  • 1
  • 11
  • 28
  • I tried, and no matter what directory I changed to, the error was still the same. – Tung Feb 03 '23 at 19:06
  • But when I run `os.getcwd()`, the current path is changed correctly based on my correction of the working directory. – Tung Feb 03 '23 at 19:08
  • That is very strange. I just replicated your exact folder structure and it works just fine. The only difference is I am running PyCharm on Windows. Maybe someone running on Mac can also try... – Scorpio Feb 04 '23 at 06:09
  • yes, I'm using Mac...hope someone can try – Tung Feb 04 '23 at 06:57
  • btw what should my working directory be? want to make sure I am right – Tung Feb 05 '23 at 06:20