Search code examples
pythonpython-3.xtracebackmodulenotfounderror

Python: 'ModuleNotFoundError' when trying to import module from the same package


I am using python 3.9 on PyCharm in Windows 10. The structure of my project is this:

/application
   /model
      /games.py
      /lock.py
      /pointClass.py
   /resources
     ...file



/lib
   ...file

On Pycharm ty program works but if i try to open it on bash (on Linux or MacOs) it gives me this error:

Traceback (most recent call last):
  File "games.py", line 16, in <module>
    from application.model.lock import RWLock
ModuleNotFoundError: No module named 'application'

In my games.py file i write this to import other file:

from application.model.lock import RWLock
from application.model.pointClass import *

How can i resolve this problem? If you wanted to look at my entire project you can go on this github repo: https://github.com/MarioAvolio/BomberFriends


Solution

  • In fact, the file games.py and lock.py and pointClass.py is in the same folder so why not importing it directly like this :

    from lock import RWLock
    from pointClass import *