问题
Often requirements show up in requirements.txt like this:
django-registration
But in INSTALLED_APPS it appears as registration. So when you import like:
from registration.signals import user_registered
This is valid but PyCharm is showing a red squiggly line under the word registration in from registration... that says "Package 'registration' is not listed in project requirements".
How can I remedy this?
UPDATE
I was able to find a way to make the warning go away but it's not a good solution. If you simply add the package name to the requirements.txt file the warning goes away, but then that requirement is not valid if you were to install with pip. For example, I'm also using pygooglevoice which is how it's written in requirements.txt but when it's imported in the code, you write:
from googlevoice import Voice
This seems weird because I use PyCharm for many projects and I'm just noticing this with a recent project I'm working on...
回答1:
This seem to be an open issue
https://youtrack.jetbrains.com/issue/PY-11963
回答2:
After seeing this phenomenon again, I did some more digging. After setting certain folders as source roots and restarting PyCharm, these reference warnings went away. I think this is a bug in PyCharm.
回答3:
JetBrains claims that this is fixed in version 2017.2:
https://youtrack.jetbrains.com/issue/PY-11963#comment=27-2248728
I can confirm this (in IntelliJ IDEA). Also, it's worth double-checking that the correct requirements file is specified in Settings -> Tools -> Python Integrated Tools -> Package requirements file
回答4:
PyCharm should be able to figure this out, but it doesn't. For now, I just add # noinspection PyPackageRequirements to each import with this warning to suppress it. I'd rather not, but it works for now.
来源:https://stackoverflow.com/questions/29025468/pycharm-not-properly-recognizing-requirements-python-django