Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

pycharm - Unresolved reference when importing from sibling sub-package with

I have following similar directory structure.

main.py
pack
   |___sub_pack1
                |__a.py
   |___sub_pack2
                |__b.py

Now inside main.py (which is my main program that I execute) I am importing like follow

from pack.sub_pack1 import a

Working fine.

Inside a.py I am importing like follow

from pack.sub_pack2 import b

At this point pycharm underlines above code as red and notifying me "Unresolved reference pack".

Now my code is working fine which should. I am curious why pycharm considering it as error and what can I do to avoid such thing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Another thing you can do if you're having trouble with "Unsolved reference" errors in PyCharm is:

  • Right-click on the Python sources directory
  • Select "Mark Directory As" > "Source Root"

Make sure you've done this for all your Python source directories.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...