PyCharm 和 Pylance 为什么无法检测到以可编辑模式安装的软件包?

huangapple go评论52阅读模式
英文:

Why are PyCharm and Pylance not detecting packages installed in editable mode?

问题

最近,诸如PyCharm和VSCode中的Pylance等代码分析工具未能检测到以可编辑模式安装的包(pip install -e <package_name>)。

这导致我无法通过在VSCode中按Ctrl键单击来导航到导入的模块,并且它未为我提供导入函数的文档字符串。

我注意到,在我的site_packages目录中,以前有一个以包名称命名的文件,现在只有一个名为__editable_package_name_finder.py的文件。

英文:

Recently, code analysis tools like PyCharm and Pylance in VSCode are not picking up packages installed in editable mode (pip install -e &lt;package_name&gt;).

This made it so I could not navigate to imported modules by Ctrl-clicking (in VSCode), and it is not providing me docstrings for imported functions.

I noticed that where in my site_packages directory there used to be a file with the package's name, now there is only a file called __editable_package_name_finder.py instead.

答案1

得分: 5

setuptools已经改变了它执行可编辑安装的方式,似乎与各种工具不兼容。有关此行为的详细解释,请参阅此页面

Setuptools提供了一个配置选项,可以继续使用旧的安装方法。可以通过以下方式之一设置此标志来进行安装:
pip install -e . --config-settings editable_mode=compat

或者在安装之前设置环境变量SETUPTOOLS_ENABLE_FEATURES=&quot;legacy-editable&quot;,尽管这种方法在此处的注释中有所限制:

> 当存在pyproject.toml文件时,较新版本的pip不再运行后备命令python setup.py develop。这意味着在使用pip安装包时设置环境变量SETUPTOOLS_ENABLE_FEATURES="legacy-editable"将不会产生任何效果。

在使用旧模式重新安装所需的包之后,您可能需要重新启动编辑器,或者在使用VSCode的情况下,运行命令<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>中的“Python: Restart language server”。

英文:

setuptools has changed the way it carries out editable installs which seems to have broken compatibility with various tools. For an in-depth explanation of the behavior refer to this page.

Setuptools provides a config option to stick to the old installation method.
Either by setting the following flag on install:
pip install -e . --config-settings editable_mode=compat

Or by setting the environment variable SETUPTOOLS_ENABLE_FEATURES=&quot;legacy-editable&quot; before installing, though this last method has the limtation explained in the note here:

> Newer versions of pip no longer run the fallback command python setup.py develop when the pyproject.toml file is present. This means that setting the environment variable SETUPTOOLS_ENABLE_FEATURES="legacy-editable" will have no effect when installing a package with pip.

After reinstalling the desired package using legacy mode, you will probably need to either restart the editor, or in the case of VSCode run the command "Python: Restart language server" in <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>

huangapple
  • 本文由 发表于 2023年5月22日 04:21:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301782.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定