This is my directory structure
--> ProjectDirectory
-->__init__.py
--> BaseDirectory
-->__init__.py
--> AnotherBaseDirectory
-->__init__.py
-->program.py
inside program.py
When i give import BaseDirectory
PyCharm is unable to recognize the package
all __init__.py
files contain __all__
variable with the python file names
What am i doing wrong?
Troubleshooting: Try installing/importing a package from the system terminal (outside of PyCharm) using the same interpreter/environment. In case you are using a virtualenv/conda environment as your Project Interpreter in PyCharm, it is enough to activate that environment in the system terminal and then do the test.
If you have setup.py in your project and you use find_packages() within it, it is necessary to have an __init__.py file in every directory for packages to be automatically found.
Without an __init__.py file, you cannot import files from another directory in a Python project.
You can try marking root directory as Sources Root. Right click on root directory, and click Mark Directory As -> Sources Root
If we set __init__.py
as a Text
file type, Pycharm was not indexing it. We need to remove __init__.py
from the Text
file type
My problem was that I had a hyphen in the package name foo-bar
, which also brings other problems with it. Replacing with an underscore: foo_bar
immediately solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With