Pycharm doesnt recognize project packages

I would suggest the following

  • Close pycharm
  • Delete the .idea folder
  • Open the project as new project
  • Make sure you have the __init__.py files where they belong (each package needs one)

It should not be necessary in this case to add anything to the pythonpath or source root manually. This is only necessary if you work on two projects with are disconnected from each other and you want them to be able to import from each other.


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.

enter image description here

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"

enter image description here

Hope this helps.

Tags:

Python

Pycharm