user1917407 user1917407 - 2 months ago 9
Python Question

How do I import a module from within a Pycharm project?

In my project, the file structure is as follows:

root/folder1/folder2/script1.py

root/folder1/folder2/script2.py

I have a statement in script2.py that says "import script1", and Pycharm says no module is found. How do I fix this?

Answer

To import as object :

from root.folder1.folder2 import script1

To import a function of your script:

from root.folder1.folder2.script1 import NameOfTheFunction

Comments