PyCharm 不愿意导入模块 [英] PyCharm not willing to import modules

查看:67
本文介绍了PyCharm 不愿意导入模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在 PyCharm 中导入模块时,代码行都会以灰色突出显示,并给出错误未使用的导入语句".我尝试导入的每个模块似乎都会发生这种情况.有谁知道这可能是什么原因造成的?

Whenever I try to import modules in PyCharm, the line of code is highlighted grey and it gives me the error "unused import statement". This seems to happen for every module I try to import. Does anyone know what could be causing this?

推荐答案

在脚本中调用这些模块后,您应该会看到那些灰显的线条变为正常颜色.

Once you call those modules in your script, you should see those greyed out lines turn to their normal color.

您可以关闭查看导入的代码检查,但我不建议您这样做,除非您绝对确定您不需要它.

You can turn off the code inspection that looks at import, but I don't advise doing that unless you're absolutely sure you don't need it.

我在设置>编辑器>颜色和字体>常规中将我的未使用的符号"更改为没有下划线的灰色.这有助于我快速查看是否有我的代码中未使用的变量或导入.

I changed my "Unused Symbol" in Settings > Editor > Colors&Fonts > General to just be grey without the underline. This helps me quickly see if I have a variable or an import that I'm not using in my code.

然后我还更改了未使用的代码检查严重性.设置 > 编辑器 > 检查 > Python > 未使用的本地我将严重性设置为信息"和在所有范围内".

Then I also changed the code inspection severity on unused. Settings > Editor > Inspections > Python > Unused local I set the severity to 'INFO' and 'In All Scopes'.

这让您仍然可以知道自己有未使用的变量,而不会将其视为错误.

This allows you to still gain the benefit of knowing you have unused variables without it treating it like an error.

正如您从我的屏幕截图中看到的,即使我导入了它们,我也没有使用 tztzinfo.我觉得这很方便.

As you can see from my screenshot, I'm not using tz or tzinfo even though I imported them. I find that pretty handy.

这篇关于PyCharm 不愿意导入模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆