0

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?

adamcircle
  • 694
  • 1
  • 10
  • 26

1 Answers1

2

To import as object :

from root.folder1.folder2 import script1

To import a function of your script:

from root.folder1.folder2.script1 import NameOfTheFunction

Vuwox
  • 2,331
  • 18
  • 33
  • One more thing, how does this work if there's a space in the folder name? – adamcircle Sep 28 '16 at 22:47
  • You should remove them or use another way to import. Look at the answer : http://stackoverflow.com/questions/9123517/how-do-you-import-a-file-in-python-with-spaces-in-the-name – Vuwox Sep 29 '16 at 17:07