0

Trying to import a class into my Python code from another .py file I've written and included in the same sub-directory, however I'm receiving the error:

ModuleNotFoundError: No module named 'main.S_DES_Functions'; 'main' is not a package

Please find below images of the layout of my Python project.

Class I'm trying to importMain file running program, trying to import class

I'm hoping this is just a really silly mistake I'm making, so if anyone can please advise what I'm doing wrong that'd be great :)

Ice Phoenix
  • 951
  • 3
  • 14
  • 33
  • 5
    python doesn't use semi colons. Also did you try [removing the dot](https://stackoverflow.com/questions/41816973/modulenotfounderror-what-does-it-mean-main-is-not-a-package)? – Paul Rooney Sep 13 '17 at 01:52
  • 1
    This may help: https://stackoverflow.com/a/20749411/4421870 and get rid of the semi colons – Mako212 Sep 13 '17 at 01:57
  • Can you see the contents of the directory in code completion look up when you type `from .`? – SkrewEverything Sep 13 '17 at 01:57
  • 1
    How are you running the code where you get the error? Are you doing `python some_script.py` where the script file is in the same package as the rest of your code? That won't work because Python won't realize the main module is in a package. A better way is to change directory to be above the package, then run `python -m package.script_module`. – Blckknght Sep 13 '17 at 02:38

1 Answers1

0

Thanks for the suggestions, I tried them however was still receiving the same error. But I managed to find a work around, similar to what is listed in this other Stack Overflow question - Unresolved reference issue in PyCharm

I basically made a new directory for my classes and set it as the directory as a "Source" for the project, which then allowed me to import it and use the classes without any issues.

Ice Phoenix
  • 951
  • 3
  • 14
  • 33