【问题标题】:Unrecognized command error when using pyinstaller after (pip) installing it [duplicate](pip)安装后使用pyinstaller时出现无法识别的命令错误[重复]
【发布时间】:2020-11-30 14:20:36
【问题描述】:

当试图找到一种将我的 python 文件“捆绑”到.exe 的好方法时,我遇到了pyinstaller。我查阅了有关如何使用它的指南,发现了这个guide。我只是使用pip install pyinstaller 安装了pyinstaller,它似乎安装得很好,但是当尝试在控制台中使用pyinstaller 时,它引发了一个错误,说'pyinstaller' is not recognized as an internal or external command, operable program or batch file. 我什至尝试将目录更改为我的文件所在的位置,但它仍然出现同样的错误。当尝试通过 pip 再次安装它时(以防发生一些错误)我收到了这条消息:

Requirement already satisfied: pyinstaller in c:\users\[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (4.1)
Requirement already satisfied: pefile>=2017.8.1; sys_platform == "win32" in c:\users\[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pyinstaller) (2019.4.18)
Requirement already satisfied: altgraph in c:\users\[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pyinstaller) (0.17)
Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in c:\users\[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pyinstaller) (2020.10)
Requirement already satisfied: setuptools in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.9_3.9.240.0_x64__qbz5n2kfra8p0\lib\site-packages (from pyinstaller) (49.2.1)
Requirement already satisfied: pywin32-ctypes>=0.2.0; sys_platform == "win32" in c:\users\w[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pyinstaller) (0.2.0)
Requirement already satisfied: future in c:\users\[me]\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pefile>=2017.8.1; sys_platform == "win32"->pyinstaller) (0.18.2)

【问题讨论】:

    标签: python pip pyinstaller


    【解决方案1】:

    尝试在命令pyinstaller 前加上python -m

    python -m PyInstaller yourscript.py
    

    如果这不起作用,请尝试使用 python3 -mpy -m

    python3 -m PyInstaller yourscript.py
    py -m PyInstaller yourscript.py
    

    【讨论】:

      【解决方案2】:

      你可以通过在python3前加前缀来执行pyinstaller

      python3 -m pyinstaller file.py
      

      如果没有前缀,请按照以下方法,

      在 Windows 中,pyinstaller 可执行文件位于

      C:\Users\USER_NAME\AppData\Roaming\Python\Python37\Scripts
                                   (or)
      C:\Program Files\Python37\Scripts
      

      并复制pyinstaller executable 路径并将其添加到Windows System Environment Variables。这可以通过

      1. 点击开始菜单中的搜索并搜索Edit System Environment Variables

      2. 点击底部的Environment variables。 点击Path,再点击edit

      3. 点击New并将复制的pyinstaller executable路径添加到path部分 然后点击OK

      4. 现在在 CMD 中检查 pyinstaller。

      快乐编码:)

      【讨论】:

        猜你喜欢
        • 2014-07-26
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        • 2021-06-05
        • 2020-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多