-1

My project structure is as below.

~/project
----maindriver.py
----/module1
--------main_code.py
----/module2
----/module3
----/module4
--------/submodule1
------------code.py
--------/submodule2

IN main_code.py I use import submodule1.code import code

I get this error: ERROR: Module Not Found "submodule1"

Do I have to check $PYTHONPATH or sys.path?

Hozefa
  • 3
  • 2
  • This import `import submodule1.code` doesn't make sense unless `submodule1` is a top level package. Could you clarify what your intended package structure is? How are you putting the top-level package(s) on the Python path? That's usually done by either installing your project as a distribution package or by relying on a particular directory being your CWD – Brian61354270 Jul 25 '23 at 18:55

1 Answers1

0

I found this on google:

To import a file from a different folder in Python, you will need to use the sys. path. append() function to add the path to the folder containing the file to the Python path. (Search for: how to import python script from another directory)

Another thing you can do is just bring the script/module (code.py) to the same directory as the script accessing it (main_code.py), unless it is necessary for code.py to be on a different directory.

Feel free to comment on my answer in case I haven't clearly answered your question. I will do what I can to help.