【pycharm】【软件包安装问题 】

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

在虚拟环境中安装软件包

  1. Press CtrlAlt S to open the IDE settings and then select Project <project name> | Python Interpreter.
    按 Ctrl Alt  
    S打开IDE设置,然后选择项目|Python解释器。

  2. Expand the list of the available interpreters and click Show All.
    展开可用解释器的列表,然后单击全部显示。

    Show all available interpreters

  3. Locate the target interpreter and copy the path to the virtual environment.
    找到目标解释器并将路径复制到虚拟环境。

    Discover the interpreter path for the selected venv

  4. Open the system terminal (not the PyCharm's built-in one) and run the following commands:
    打开系统终端(不是PyCharm内置的终端)并运行以下命令:

    Windows
    macOS 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>

    Installing a Python package on a virtual environment

  5. Inspect and parse the results.
    检查并解析结果。

Install a package on a conda environment

在conda环境中安装软件包

  1. 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.
      找到解释器,按

       ,然后复制环境名称。

  2. Open the system terminal (not the PyCharm's built-in one) and run the following commands:
    打开系统终端(不是PyCharm内置的终端)并运行以下命令:

    Windows

    conda < 4.6

    conda >= 4.6

    activate <conda env name>
    conda install <package name>
    conda activate <conda env name>
    conda install <package name>
    macOS and Linux

    conda < 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文档。

    Installing a Python package on a virtual environment

    One of the possible failure cases occurs when the target package is not available in the repositories supported by the conda package manager.
    当conda包管理器支持的存储库中没有目标包时,可能会出现一种失败情况。

    Fail to install a package on a conda environment

  3. Inspect and parse the results.
    检查并解析结果。

Install a package on a system interpreter
在系统解释器上安装软件包

  1. 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解释器。

  2. Expand the list of the available interpreters and click Show All.
    展开可用解释器的列表,然后单击全部显示。

    Show all available interpreters

  3. Locate the interpreter and copy the path.
    找到解释器并复制路径。

    Discover the interpreter path for the selected venv

  4. Open the system terminal (not the PyCharm's built-in one) and run the following commands:
    打开系统终端(不是PyCharm内置的终端)并运行以下命令:

    <interpreter path> -m pip install <package name>

    Installing a Python package on a system environment

    You might need the admin privileges to install packages on a system interpreter.
    您可能需要管理员权限才能在系统解释器上安装软件包。

  5. 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.
无法安装该软件包,因为Python版本不满足软件包要求。

Try to create another Python interpreter that is based on the Python version that meets the requirement.
尝试创建另一个基于满足要求的Python版本的Python解释器。

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, sudo pip install <package name>.
尝试使用超级用户权限安装软件包,例如 sudo pip install <package name> 。

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.
无法安装此包,因为选定的包管理器支持的存储库中没有此包。例如:你正在尝试安装一个在conda软件包管理器仓库中不可用的软件包。

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.
尝试为您的项目配置另一种类型的Python解释器,并在其上安装该软件包。请参阅配置Python解释器中的如何添加和修改Python解释器。

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.
在PyCharm问题跟踪器中提交一个问题,并提供有关该案例的详细信息,包括所有控制台输出,错误消息和屏幕截图,这些屏幕截图表明您试图在终端和项目设置中或Python Packages工具窗口中的同一解释器上安装包。

Review typical cases

 回顾典型案例

Error message 错误消息

Related package 相关套餐

Workaround 解决方法

Reference 参考

fatal error: 'SDL.h' file not found

pygame, pysc2 pygame,pysc2

Installation fails because the package requires SDL, and pip cannot detect it. Try the following commands:
安装失败,因为软件包需要SDL,而pip无法检测到它。请尝试以下命令:

brew install sdl sdl_image sdl_mixer sdl_ttf portmidi;
pip3 install pygame;
pip install pygame

python - pip install pygame - SDL.h file not found - Stack Overflow

Cannot open include file: 'portaudio.h'

pyaudio 皮亚迪奥

Try to run the following commands using the admin privileges:
尝试使用管理员权限运行以下命令:

pip install pipwin
pipwin install pyaudio

python - How to fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory" - Stack Overflow

https://www.programmersought.com/article/5816775591/

SSL module in Python is not available

any package 任何包

Install an openssl library by the way specific to your operating system. See the detailed solutions.
通过特定于您的操作系统的方式安装openssl库。查看详细解决方案。

  • 8
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

资源存储库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值