英文:
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 <package_name>
).
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="legacy-editable"
,尽管这种方法在此处的注释中有所限制:
> 当存在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="legacy-editable"
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论