• 【学习笔记】pip安装pyinstaller报错问题


    pip 安装 pyinstaller 报错问题及解决方案

    引言

    PyInstaller 是一个强大的工具,它能够将 Python 应用程序及其依赖项打包成一个可执行的软件包。这样,用户无需安装 Python 解释器或任何模块,即可在不同平台上运行打包后的应用程序。本文将详细讨论使用 pip 安装 PyInstaller 时可能遇到的问题及其解决方案。

    PyInstaller 简介

    PyInstaller 将 Python 应用程序及其所有依赖项捆绑到一个软件包中。 用户无需安装 Python 解释器或任何模块,即可运行打包后的应用程序。 PyInstaller 支持 Python 3.8 及更新版本,并能正确捆绑 numpy、matplotlib、PyQt、wxPython 等许多主要 Python 软件包。

    PyInstaller 针对 Windows、MacOS X和Linux进行了测试。然而,它不是一个交叉编译器,要制作Windows应用,你需要在 Windows 上运行 PyInstaller,要制作 Linux 应用,你需要在 Linux 上运行它。

    安装 PyInstaller

    通常,我们可以通过 pip 命令轻松安装 PyInstaller:

    pip install pyinstaller
    

    常见安装错误及原因

    在尝试安装 PyInstaller 时,可能会遇到如下错误:

    $ pip install pyinstaller
    Collecting pyinstaller
      WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')"))': /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl
      WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')"))': /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl
      WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f72c8993b20>: Failed to establish a new connection: [Errno 111] Connection refused')': /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl
      WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')"))': /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl
      WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')"))': /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl
    ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')")))
    

    出现了 ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool 这样的错误。

    重试多次后,还是这样。

    解决方案:使用国内镜像源

    面对此类问题,一个有效的解决方案是切换到国内镜像源进行安装。国内镜像源通常提供更快的下载速度和更稳定的连接。以下是使用清华大学提供的 PyPI 镜像源安装 PyInstaller 的示例:

    $ pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
    Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
    Collecting pyinstaller
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2a/e0/9df946cd387947176f2dd449439f8de1d6f7e41bab0a460750cf19f3ea8d/pyinstaller-6.7.0-py3-none-manylinux2014_x86_64.whl (682 kB)
         |████████████████████████████████| 682 kB 744 kB/s
    Collecting importlib-metadata>=4.6; python_version < "3.10"
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/0a/679461c511447ffaf176567d5c496d1de27cbe34a87df6677d7171b2fbd4/importlib_metadata-7.1.0-py3-none-any.whl (24 kB)
    Requirement already satisfied: packaging>=22.0 in /home/hongjh/.local/lib/python3.8/site-packages (from pyinstaller) (23.2)
    Collecting pyinstaller-hooks-contrib>=2024.6
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2e/84/079d3bd411f591d825dca78b83093fcc9631ea2f887cb01fa9e19f4c619f/pyinstaller_hooks_contrib-2024.6-py2.py3-none-any.whl (339 kB)
         |████████████████████████████████| 339 kB 1.2 MB/s
    Requirement already satisfied: setuptools>=42.0.0 in /usr/lib/python3/dist-packages (from pyinstaller) (45.2.0)
    Collecting altgraph
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4d/3f/3bc3f1d83f6e4a7fcb834d3720544ca597590425be5ba9db032b2bf322a2/altgraph-0.17.4-py2.py3-none-any.whl (21 kB)
    Requirement already satisfied: zipp>=0.5 in /home/hongjh/.local/lib/python3.8/site-packages (from importlib-metadata>=4.6; python_version < "3.10"->pyinstaller) (3.17.0)
    Installing collected packages: importlib-metadata, pyinstaller-hooks-contrib, altgraph, pyinstaller
    Successfully installed altgraph-0.17.4 importlib-metadata-7.1.0 pyinstaller-6.7.0 pyinstaller-hooks-contrib-2024.6
    

    完成下载安装。

    使用国内镜像源后,安装过程将更加顺畅,减少了因网络问题导致的失败几率。

    安装验证

    安装完成后,我们可以通过查看 PyInstaller 的版本来验证是否安装成功:

    查看版本,看是否成功安装:

    $ pyinstaller --version
    6.7.0
    

    如果命令返回了正确的版本号,如 “6.7.0”,则表示 PyInstaller 已成功安装。

    结语

    PyInstaller 是 Python 开发者在打包应用程序时的重要工具。通过本文的介绍,我们了解到了在安装过程中可能遇到的问题以及如何通过使用国内镜像源来解决这些问题。希望这些信息能够帮助开发者们更顺利地使用 PyInstaller。


    本文链接:https://blog.csdn.net/u012028275/article/details/139454477

  • 相关阅读:
    Kafka多维度调优
    Flutter实现ControlExecutor进行多个异步任务执行时监听状态并可指定最后执行的异步并在指定的异步执行完毕后结束executor并回调。
    练习题57:接口的语法特征
    c++的数据类型的引用(三种方式有一些区别)
    sharding-jdbc读写分离
    windows下VS配置NISwGSP
    PostgreSQL - 基于pg_basebackup实现主从流复制
    离散傅里叶变换(DFT)和基2快速傅里叶变换(FFT)算法的C语言实现
    从网约车平台合规问题看企业合规难题如何破解
    98.验证二叉搜索树
  • 原文地址:https://blog.csdn.net/u012028275/article/details/139454477