This question has been asked before - but i could not solve it with any of the answers. I opned a project folder in pycharm (note that the project folder is not in the ../PycharmProject/...
directory.
My structure is super basic:
project_title (folder)
|--src (folder)
|-- app.py
|-- pipeline_tools (folder)
|-- helpers.py
|-- other modules
I tried all possible solutions and combinations but when in app.py
i try to import a function from either modules in tools
I get errors.
Additionally, Pycharm underlines in red the following statement:
1) from pipeline_tools.helpers import a_certain_function
(red underline with "Unresolved reference")
But the following gives me no red:
2) from .pipeline_tools.helpers import a_certain_function
(no red underline, note the relative import)
The fact that I have or not a __init__.py
inside the modules changes nothing - I still get the following two errors:
For 1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/gabriele/pycharm-2019.1.1/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pipeline_tools'
for 2)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/gabriele/pycharm-2019.1.1/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named '__main__.pipeline_tools'; '__main__' is not a package
Stuff I made sure I tried:
1) Go to settings > Project Structure
check content root
is .../project_title
and marked it as "source" - it's blue.
2) Add __init__.py
in the pipeline_tools
folder and in the /src
folder, tried all possible combinations.
3) Use the below code to check the path to the project folder is part of the path string - it is at the end
import sys
print(sys.path)
4) Use the below code to move the project path to the beginning of the sys.path:
sys.path.insert(0,'path/to/project_title')
5) Just tried to print PYTHONPATH
like this:
os.environ['PYTHONPATH'].split(os.pathsep)
and the directory of my project is not in it
I am a bit at a loss right now. Have no idea what is going on.