I have an issue where I dont get the solution. I also look here in stackoverflow.com, tried different solutions but nothing helps.
My project struct looks like this:
-MyFolder
----MySubFolder
------MySubFolder.py
------__init__.py
----MyFolder.py
----__init__.py
To be clear. MyFolder.py and his init.py are below MyFolder and above MySubFolder.
In a different project, I import MyFolder, but PyCharm doesn´t recognized MyFolder as a Package. MyFolder is part of PYTHONPATH, so it should be found.
In the init.py inside MyFolder, it looks like:
import os
import sys
fpath = os.path.join(os.path.dirname(__file__))
sys.path.append(fpath)
from MyFolder import *
and in MySubFolder
import os
import sys
fpath = os.path.join(os.path.dirname(__file__))
sys.path.append(fpath)
from MySubFolder import *
But when I do
from MyFolder.MyFolder import *
then it working. But my goal is only to import MyFolder
sys.pathmodifications are very often not necessary, rather a red flag. I would remove all of them if I were you. There is very likely a much simpler way to achieve what you want to do. -- It would be better if you used clearer names for your example. Having aMyFolderdirectory and aMyFolder.pyfile make things very hard to follow.