[Django]-PyCharm Not Properly Recognizing Requirements – Python, Django

20👍

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.

20👍

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

👤iver56

15👍

This seem to be an open issue

https://youtrack.jetbrains.com/issue/PY-11963

👤MrJ

2👍

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.

-1👍

This issue can be fixed using the following commands in the terminal (using linux, not sure if this will work on windows, but I see no reason why it shouldn’t, I haven’t tried on windows.)

If you haven’t created a requirements.txt file already

touch requirements.txt

This should do the trick

pip freeze > requirements.txt
pip install flask

For better understanding, I recommend reading this

https://boscacci.medium.com/why-and-how-to-make-a-requirements-txt-f329c685181e

Leave a comment