Import unresolved references
已回答
I have import statements at the beginning of my PY file with red squiggly lines under them - they do not cause the script to fail). When I hover over the import, is says:
"unresolved reference - the inspection detects names that should resolve but don't. Due to dynamic dispatch and duck type, this is possible in a useful but limited number of cases. Top-level and class-level items are supported better than some instance items."
This is not fatal since the script typically runs fine but I occasionally get weird errors with imports. Why does this happen? How can I correct it? Thank you!
请先登录再写评论。
Hi Alexandr, looks like a PyCharm's bug. Which version do you use? Could you please copy this function to a new project to check if the warning will be shown there as well? I wonder if this is a project specific issue.
I'd like to add that it's particularly suspicious that the project with its respective venv is created inside the installation directory of a Python distribution. It's not a typical scenario and might confuse our code insight in terms of the difference between projects sources and interpreter's stdlib.
The miracle happened.
I copied the code to a new file in same project and the warning disappeared.
Pavel and Mikhail, thank you!
It's odd that it happens depending on a file this code occurs in, though. Please create an issue in our tracker with IDE log attached (Help | Show Log in Files) if it happens again.
If something like that happens again I will immediately report about it.
hi every body! This was solved. CAUSE IS PATH IN IMPORT CODE ANOTHER FORDER PROJECT!! Example path import from detect import detection . When code write src folder
you can repair FROM src.detect import detection (from detect import detection)
Hi Tai94bn,
Glad to hear that the problem was solved. I'm afraid I don't understand what I should do to fix it. Would you mind providing more detailed instructions.
Thanks!
i have used existed python code in PyCharm IDE, when i run the code i got an error : Unresolved reference with red squiggly lines under them. Please can you help me.
i am using
1) Pycharm-community-2019.1.2
2) python-3.7.3-amd64
3) Windows 10
interpreter
Right-click lib folder -> Mark Directory as ... -> Source Root. PyCharm adds all Source Roots to PYTHONPATH by default.
Also note that you have both "mrmr" package and "mrmr" module in your project (without ".py" extension). Even though absence of the extension allows to avoid import ambiguity here it's still quite confusing, and, by the way, associating "mrmr" with Python file type makes it so in every project since it's an application-wide setting.
It works, mark directory as 【Source Root】.
How to correct the error unresolved reference print?