PyCharm CE 2018.2.3 doe not recognizes project content root

Completed
I have PyCharm Community Edition 2018.2.3 and the following package structure:

folder1
    |
    |-> Package1
            |
            |-> __init__.py
            |-> Package2
                    |
                    |-> class1.py
folder2
    |
    |-> Package1
            |
            |-> __init__.py
            |-> Package3
                    |
                    |-> class2.py
            
folder3
    |
    |-> Package1
            |
            |-> __init__.py
            |-> Package4
                    |
                    |-> class3.py
                    |-> class4.py

I have to add that the packages (Package2, Package3 and Package4) are added to Package1 in runtime.
So, Package1 is one big package distributed into several folders.
All the __init__.py are empty, except for the one that imports all the other packages into this one.

When I use python I can do the following without problems:

import Package1.Package2.class1
from Package1.Package3 import class2
from Package1 import Package4

I have added, as the project content root, the following folders:

folder1\Package1
folder2\Package1
folder3\Package1

But, when I open the file with the previous imports, PyCharm cannot find the packages and classes from the last 2 folders (folder2 and folder3).
If I put any of those, as content root, first; then the others are not recognized by PyCharm and thus, it cannot find the declarations inside them.

Is there a way to achieve that PyCharm recognizes the packages and classes from all the folders, so Package1 is a big package?
0
3 comments

Hi Mcksysargentina,

Could you please provide an example of successful running it in the system terminal (outside of PyCharm) with the same interpreter and unsuccessful running in PyCharm?
Please also attach a screenshot with your Project Structure (Settings/Preferences | Project | Project Structure).

0
Avatar
Permanently deleted user

The previous was an example since my project is far more complex, but I checked everything again and I realized that I was doing it wrong. The "__path__" variable from "Package1" was initialized correctly, and it worked fine under pyhon. But I made a mistake when selecting the root content: I selected 1 folder up, so PyCharm couldn't find any packages since there was no __init__.py in the selected folder (1 was 1 folder "down").

Sorry for the inconvenience!

0

No problem, I'm glad that it works now.

0

Please sign in to leave a comment.