3

Lets assume I have opened project I am working on as project/some_package. The problem is that in namespace some_package I have installed some another projects within the same namespace. PyCharm can not resolve origin of those modules - even if interpreter does it well.

Example

My project:

.
└── project
    └── some_package
        ├── main.py
        └── some_file.py

Site packages:

.
└── some_package
    ├── lib_one
    └── lib_two

Then in main.py (which interpreter gets well) but on imports from site packages pycharm raises "can not find reference"

from some_package.some_file import something  # <---- local

from some_package.lib_one import *  # <---- from site packages
from some_package.lib_two import *  # <---- from site packages

Ishinomori
  • 229
  • 1
  • 6
  • Check the working directory, I guess since it sees it as a folder there it tries to import the folder and not from site packages, try to run the interpreter from the same working directory and you should see the same problem. – Uriya Harpeness Sep 29 '20 at 06:38
  • It is very similar to the circular import errors, just that the file is replaced by the folder. – Divyessh Sep 29 '20 at 06:39
  • 1
    Right click on that directory and select `Mark Directory as > Sources Root`. – mx0 Sep 29 '20 at 06:40
  • @UriyaHarpeness interpreter gets it well from any directory – Ishinomori Sep 29 '20 at 06:53
  • @mx0 no difference - still the one from site packages is not visiable by pycharm – Ishinomori Sep 29 '20 at 06:54

1 Answers1

0

You need to setup your python packages as "Namespace Package" if you want to split sub-packages across multiple directories

See:

David
  • 135
  • 3
  • 7