在(pip)安装后使用pyinstaller时出现无法识别的命令错误

2024-04-20 15:21:27 发布

您现在位置:Python中文网/ 问答频道 /正文

当试图找到一种将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)

Tags: inpackageslocalsiterequirementusersappdatame
2条回答

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

python -m PyInstaller yourscript.py

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

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

您可以通过在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并在path部分添加复制的pyinstaller executable路径 然后单击OK

  4. 现在检查CMD中的pyinstaller

快乐编码:)

相关问题 更多 >