简体   繁体   English

Package 导入命名不同于 requirements.txt 导致 PyCharm 警告

[英]Package import named differently than in requirements.txt causes PyCharm warning

This issue does not cause an actual problem when running the code, but rather is an issue of a PyCharm warning that I would like resolved so other programmers working on the project do not have to waste time investigating.此问题在运行代码时不会导致实际问题,而是一个 PyCharm 警告问题,我希望解决此问题,以便其他从事该项目的程序员不必浪费时间进行调查。 The issue is that I have an import statement referencing an installed package:问题是我有一个引用已安装 package 的导入语句:

import barcode

However, in my requirements.txt file the package is listed as:但是,在我的 requirements.txt 文件中,package 被列为:

python-barcode==0.10.0

This causes PyCharm to generate a warning stating that:这会导致 PyCharm 生成警告,指出:

Package containing module 'barcode' is not listed in project requirements less... (Ctrl+F1) Inspection info: This inspection warns about imported or required, but not installed packages. Package 包含模块 'barcode' 未在项目要求中列出... (Ctrl+F1) 检查信息:此检查警告有关导入或需要但未安装的包。

I was wondering if anyone knew of a way I could permanently avoid this warning for future programmers working in their own IDE, perhaps via a directive in the requirements.txt file, or something to that effect.我想知道是否有人知道一种方法,我可以通过 requirements.txt 文件中的指令或类似的方式来永久避免在他们自己的 IDE 中工作的未来程序员的这个警告。

To handle such cases PyCharm team has scrapped PyPI once, the result mapping is bundled with the IDE and is stored in <PyCharm_installation_path>/helpers/tools/packages .为了处理这种情况,PyCharm 团队已经废弃 PyPI 一次,结果映射与 IDE 捆绑在一起并存储在<PyCharm_installation_path>/helpers/tools/packages中。 It was a while ago so new packages are missing.不久前,所以缺少新的软件包。 See the ticket in PyCharm's bug tracker https://youtrack.jetbrains.com/issue/PY-27985请参阅 PyCharm 的错误跟踪器https://youtrack.jetbrains.com/issue/PY-27985中的票证

Feel free to edit helpers/tools/packages manually and File |随意手动编辑helpers/tools/packagesFile | Invalidate Cache & Restart to apply changes.使缓存无效并重新启动以应用更改。


Update: in PyCharm 2020.3.x the packages list is located in plugins\python\lib\python.jar archive.更新:在 PyCharm 2020.3.x 中,包列表位于plugins\python\lib\python.jar存档中。 File tools\packages inside it.里面的文件tools\packages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM