Pycharm doesn't recognize the packages of my project's modules.
I noticed there are already quite some questions on this, but I tried all the given solutions and nothing works.
I tried:
- Mark directory as source root
& checking Add sources root to pythonpath
- Opening a different project and then reopening the original one to make pycharm reindex the packages
Any suggestions?
I went over the following questions
PyCharm does not recognize modules installed in development mode
Pycharm not recognizing packages even when __init__.py exits
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.
Try to create another Python interpreter that is based on the Python version that meets the requirement. The package cannot be installed because you don't have permissions to install it. Try to install the package using super-user privileges, for example, sudo pip install <package name> .
Ok it is quite funny to answer my own question, but I understood that is the encouraged way to go if you actually found the answer.
So what was causing this problem was that __init__.py
was listed as a text file in Pycharm settings.
If you go to Settings | File Types |
Select Text
you see a list of file names/extensions that Pycharm recognizes as text.
I think this happened because I created a file named __init__
without file extension, and later changed it to __init__.py
Removing it from there fixed the issue.
Just in case people got here with a similar trouble as I am. I had all files __init__.py
correctly but pycharm didn't recognize those package properly. Finally, this following way worked for me:
In pycharm, 1. right click on a base folder of your code 2. Choose "make Directory as" 3. Choose "Sources Root"
Hope this helps.
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