Python 如何在 PyCharm 中为所有项目安装包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47769641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install packages in PyCharm for all projects?
提问by Giladbi
I use PyCharm and all the initial settings are okay.Simple package installation is working. Then why do I need to reinstall a package for each project? Is there any way to install the packages for all projects from now on?
我使用 PyCharm 并且所有初始设置都可以。简单的包安装正在运行。那为什么我需要为每个项目重新安装一个包?有没有办法从现在开始为所有项目安装包?
回答by bgse
This is depending on your project settings, the project interpreter to be specific.
这取决于你的项目设置,具体的项目解释器。
The project interpreter can be set to one of the following:
项目解释器可以设置为以下之一:
- an interpreter installed globally on your system
- an interpreter in a shared
virtual environment
- an interpreter in a
virtual environment
associated with a project
- 在您的系统上全局安装的解释器
- 共享中的口译员
virtual environment
virtual environment
与项目相关的口译员
Now the approach I'd recommend would be to create a shared virtual environment
where you install your packages to, and use this environment for all your project.
现在我推荐的方法是创建一个共享的virtual environment
安装包的位置,并在所有项目中使用这个环境。
That way, you have the desired result of needing to install your packages only once, but still have an environment isolated from your system environment.
这样,您就可以得到所需的结果,即只需要安装一次软件包,但仍然有一个与系统环境隔离的环境。
To create such an environment, follow these steps:
要创建这样的环境,请执行以下步骤:
- Settings -> Project -> Project Interpreter
- Click the cogwheel / gear icon right-side the interpreter dropdown
- Select "Add Local..." -> Virtualenv Environment
- Select a path as a root directory for the new environment
- Select base interpreter you want to use
- Tick the checkbox "Make available to all projects"
- Click the "OK" button to save the new environment
- 设置 -> 项目 -> 项目解释器
- 单击解释器下拉列表右侧的齿轮/齿轮图标
- 选择“添加本地...”-> Virtualenv 环境
- 选择一个路径作为新环境的根目录
- 选择要使用的基本解释器
- 勾选“对所有项目可用”复选框
- 单击“确定”按钮保存新环境