如何全局安装Python(dev)依赖关系,这样我就不必在每个venv中都重新安装它们? [英] How to install Python (dev) dependencies globally so that I don't have to reinstall them in every venv?
问题描述
我希望在为每个项目创建的每个venv(虚拟环境)中都可以使用一些Python依赖项.例如black,flake8和pytest.那有可能吗,如果可以的话,如何实现呢?
There are a few Python dependencies that I would like to be available in every venv (virtual environment) that I create for each project. For example black, flake8 and pytest. Is that possible and if so, how to achieve that?
我想在主要的Python安装下安装这三个一次,相反,我必须在启动新项目时在我创建的每个venv中重新安装所有它们.当使用VSCode时,当您切换到尚未安装这些软件包的venv时,会弹出弹出式窗口,提示未安装Linter flake8"或"...未安装black",这特别烦人.
I'd like to install these three once under my main Python installation, instead I have to reinstall all of them in every venv that I create when I start a new project. This is specially annoying when using VSCode which throws popups complaining about "Linter flake8 is not installed" or "...black is not installed", etc. when you switch to a venv where you haven't installed these packages.
推荐答案
一个可能的解决方案是,
- 停用虚拟环境.
- 安装需要全局可用的所有软件包.
- 再次激活虚拟环境.
-
确保您启用了从全局继承包
- Deactivate virtual environment.
- Install all packages which you need to be available globally.
- Again activate virtual environment.
make sure you enable inherit package from global
- How do I install a pip package globally instead of locally?
- What does sudo -H do?
One Possible solution would be,
注意:有关更多信息,请参考这些SO线程.
Note: Please refer to these SO threads as well for more information.
这篇关于如何全局安装Python(dev)依赖关系,这样我就不必在每个venv中都重新安装它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!