Package installation issues
软件包安装问题
You might encounter a problem when installing a Python package in the project settings or in the Python Package tool window. Eventually, most of the issues are out of IDE control as PyCharm uses the pip package manager to perform the actual installation.
在项目设置或Python Package工具窗口中安装Python包时可能会遇到问题。最终,大多数问题都超出了IDE的控制,因为PyCharm使用pip包管理器来执行实际安装。
This article provides troubleshooting tips and covers some typical cases.
本文提供故障排除提示并介绍一些典型案例。
Install a package using the Terminal
使用终端安装软件包
The most viable troubleshooting action is to try installing the problematic package on the selected Python interpreter using the terminal. If you get an identical error message, then the problem is not in the IDE and you should review the rationales and typical cases, or search for a solution on the Internet.
最可行的故障排除操作是尝试使用终端在选定的Python解释器上安装有问题的软件包。如果出现相同的错误消息,则问题不在IDE中,您应该查看基本原理和典型情况,或者在Internet上搜索解决方案。
Install a package on a virtual environment
在虚拟环境中安装软件包
-
Press CtrlAlt S to open the IDE settings and then select Project <project name> | Python Interpreter.
按 Ctrl Alt S打开IDE设置,然后选择项目|Python解释器。 -
Expand the list of the available interpreters and click Show All.
展开可用解释器的列表,然后单击全部显示。 -
Locate the target interpreter and copy the path to the virtual environment.
找到目标解释器并将路径复制到虚拟环境。 -
Open the system terminal (not the PyCharm's built-in one) and run the following commands:
打开系统终端(不是PyCharm内置的终端)并运行以下命令:WindowsmacOS and Linux macOS和Linux<span style="background-color:var(--wh-color-black-t5)"><span style="color:var(--wh-color-text-main)"><code><span style="color:#000000">source</span> <span style="color:#9a6e3a"><</span>venv path<span style="color:#9a6e3a">></span>/Scripts/activate pip <span style="color:#00627a">install</span> <span style="color:#9a6e3a"><</span>package name<span style="color:#9a6e3a">></span></code></span></span>
-
Inspect and parse the results.
检查并解析结果。
Install a package on a conda environment
在conda环境中安装软件包
-
If you didn't change the default conda environment name when configuring the interpreter, you can use the project name. Otherwise, do the following:
如果在配置解释器时没有更改默认conda环境名称,则可以使用项目名称。否则,请执行以下操作:-
Press CtrlAlt S and go to Project: <project name> | Python Interpreter.
按 Ctrl Alt S并转到项目:|Python解释器。 -
Expand the list of the project interpreters and scroll it down, then select Show All.
展开项目解释器列表并向下滚动,然后选择Show All。 -
Locate the interpreter, press
Rename, and copy the environment name.
找到解释器,按,然后复制环境名称。
-
-
Open the system terminal (not the PyCharm's built-in one) and run the following commands:
打开系统终端(不是PyCharm内置的终端)并运行以下命令:Windowsconda < 4.6
conda >= 4.6
activate <conda env name> conda install <package name>
conda activate <conda env name> conda install <package name>
macOS and Linuxconda < 4.6
conda >= 4.6
source activate <conda env name> conda install <package name>
conda activate <conda env name> conda install <package name>
For more information about activating an environment, refer to conda documentation.
有关激活环境的更多信息,请参阅conda文档。One of the possible failure cases occurs when the target package is not available in the repositories supported by the conda package manager.
当conda包管理器支持的存储库中没有目标包时,可能会出现一种失败情况。 -
Inspect and parse the results.
检查并解析结果。
Install a package on a system interpreter
在系统解释器上安装软件包
-
To check the path of the currently selected system interpreter that you were trying to install a package on, press CtrlAlt0S and go to Project: <project name> | Python Interpreter.
要检查当前选择的系统解释器的路径,您正尝试在其上安装软件包,请按 Ctrl Alt 0S 并转到Project:|Python解释器。 -
Expand the list of the available interpreters and click Show All.
展开可用解释器的列表,然后单击全部显示。 -
Locate the interpreter and copy the path.
找到解释器并复制路径。 -
Open the system terminal (not the PyCharm's built-in one) and run the following commands:
打开系统终端(不是PyCharm内置的终端)并运行以下命令:<interpreter path> -m pip install <package name>
You might need the admin privileges to install packages on a system interpreter.
您可能需要管理员权限才能在系统解释器上安装软件包。 -
Inspect and parse the results.
检查并解析结果。
Parse the results
解析结果
Result 结果 | Action 行动 |
---|---|
The package cannot be installed because the Python version doesn't satisfy the package requirement. | Try to create another Python interpreter that is based on the Python version that meets the requirement. |
The package cannot be installed because you don't have permissions to install it. | Try to install the package using super-user privileges, for example, |
The package cannot be installed because the package is not available in the repository that is supported by the selected package manager. Example: you're trying to install a package that is not available in the conda package manager repositories. | Try to configure another type of Python interpreter for your project and install the package on it. See how to add and modify a Python interpreter in Configure a Python interpreter. |
The package cannot be installed and it matches one of the typical package installation failure cases. | Check the cases and apply related workarounds. |
The package is successfully installed. | File an issue in the PyCharm issue tracker and provide explicit details about the case including all console output, error messages, and screenshots indicating that you tried to install the package on the same interpreter in the terminal and in the project settings or in the Python Packages tool window. |
Review typical cases
回顾典型案例
Error message 错误消息 | Related package 相关套餐 | Workaround 解决方法 | Reference 参考 |
---|---|---|---|
| pygame, pysc2 pygame,pysc2 | Installation fails because the package requires SDL, and pip cannot detect it. Try the following commands:
| python - pip install pygame - SDL.h file not found - Stack Overflow |
| pyaudio 皮亚迪奥 | Try to run the following commands using the admin privileges:
| |
| any package 任何包 | Install an openssl library by the way specific to your operating system. See the detailed solutions. |