本文介绍了PyCharm无法正确识别需求-Python,Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常这样的要求显示在 requirements.txt 中:

Often requirements show up in requirements.txt like this:

django-注册

但是在 INSTALLED_APPS 中显示为 registration 。因此,当您像这样导入时:

But in INSTALLED_APPS it appears as registration. So when you import like:

from registration.signals import user_registered

这是有效的,但PyCharm在注册中中的 registration 字下显示了一条红色的波浪线... 说项目要求中未列出软件包'registration'。

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".

我该如何解决?

更新

我能够找到使警告消失的方法,但这不是一个好的解决方案。如果仅将软件包名称添加到 requirements.txt 文件中,警告就会消失,但是如果使用进行安装,则该要求无效点。例如,我还使用了 pygooglevoice ,这是在 requirements.txt 中编写的,但是在导入到代码,您输入:

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

这似乎很奇怪,因为我在许多项目中都使用了PyCharm,而我只是在最近正在研究的项目中注意到这一点...

This seems weird because I use PyCharm for many projects and I'm just noticing this with a recent project I'm working on...

推荐答案

再次看到这种现象后,我做了一些进一步的研究。将某些文件夹设置为源根目录并重新启动PyCharm之后,这些参考警告就消失了。我认为这是PyCharm中的错误。

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.

这篇关于PyCharm无法正确识别需求-Python,Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 13:35