Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm doesnt recognize project packages

Tags:

python

pycharm

Pycharm doesn't recognize the packages of my project's modules.

enter image description here

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

like image 689
Kemeia Avatar asked Oct 22 '17 12:10

Kemeia


People also ask

Why is PyCharm not importing modules?

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.

Why can't I install packages in PyCharm?

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> .


2 Answers

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.

like image 98
Kemeia Avatar answered Sep 30 '22 18:09

Kemeia


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.

like image 42
sonvx Avatar answered Sep 30 '22 17:09

sonvx