Pyinstaller未被识别为内部或外部命令

40

我试图在命令行中使用pyinstaller,但是收到了错误:

C:\Users\username>pyinstaller
'pyinstaller' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\username>

当我在python的Scripts文件夹中使用这个命令时,它能正常工作:

Translated Text:

当我在Python的Scripts文件夹中使用此命令时,它有效:

C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pyinstaller
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
                   [--add-data <SRC;DEST or SRC:DEST>]
                   [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
                   [--hidden-import MODULENAME]
                   [--additional-hooks-dir HOOKSPATH]
                   [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
                   [--key KEY] [-d] [-s] [--noupx] [-c] [-w]
                   [-i <FILE.ico or FILE.exe,ID or FILE.icns>]
                   [--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
                   [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                   [--win-no-prefer-redirects]
                   [--osx-bundle-identifier BUNDLE_IDENTIFIER]
                   [--distpath DIR] [--workpath WORKPATH] [-y]
                   [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
                   [--upx UPX]
                   scriptname [scriptname ...]
pyinstaller: error: the following arguments are required: scriptname

C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>

如何解决这个问题?

19个回答

42

我已正确配置了我的脚本路径,我必须运行python -m PyInstaller script.py才能使其工作。

对于每个脚本,我都需要遵循这个模式:python -m [脚本名称] [参数]

Python 版本 3.10.0


PyInstaller的"P"和"I"需要大写。 - Fathy
2
啊啊啊,区分大小写... - Andrew

37

你需要修改你的用户PATH环境变量,以包含 C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python36-32\Scripts

如何添加/修改您的PATH环境变量,请参阅这个链接


你可以这样缩短路径 - %LocalAppData%\Programs\Python\Python36-32\Scripts - Gangula
但对于我来说,该文件夹在AppData/roaming文件夹中而不是Appdata/local。因此我使用了- %AppData%\Python\Python311\Scripts - Gangula

9

将“pyinstaller.exe”复制到您要转换的.py文件所在的文件夹中。完成后,只需删除“pyinstaller.exe”。祝你好运。


1
如果你经常需要移动一个可执行文件,那么这真的很麻烦。相比之下,设置路径变量更加优雅。 - Plegeus

9

首先,您需要知道pyinstaller位于哪里。 在我的情况下,我运行了

pip uninstall pyinstaller

在卸载之前,它会询问您是否要删除以下文件...

c:\users\USERNAME\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\scripts\pyinstaller.exe

太好了! 现在你知道了如何使用pyinstaller, 只需输入“No”并退出卸载,因为我们的目的只是获取路径。 现在将此路径添加到PATH环境变量中即可。

c:\users\USERNAME\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\scripts\

如何更改PATH变量,请查看此处


8

对于Python 3.7版本,你需要将AppData/Roaming目录下的Scripts文件夹(%appdata%)添加到PATH变量中。

C:\Users\%USERNAME%\AppData\Roaming\Python\Python37\Scripts


6

这个解决方案适用于Python 3.9

首先找到pyinstaller.exe的位置。为了做到这一点,您可以尝试这个技巧:(不要按下“y”,只需查看上面的内容并复制您要查找的路径)

pip uninstall pyinstaller

在输入任何内容之前,它会显示pyinstaller.exe的路径。然后将该位置复制并在终端上运行此命令:(这是一个示例)


python C:\Users\[YOUR_USER_NAME]\AppData\...Scripts\pyinstaller.exe --onefile [your_script_name.py]

6
如果您正在使用 Python 3.10 或更高版本,则 PyInstaller 可能未添加到您的 Path 变量中。为避免所有这些设置,您可以简单地运行:
python -m PyInstaller [path to your file] [args]

例如,我运行了。
python -m PyInstaller ./frontend.py --onefile

这对我来说很有效,截至2023年11月。谢谢! - undefined

3
前往路径 "C:\Users\Username\anaconda3\Scripts",复制 "pyinstaller.exe" 并将其粘贴到您想使用 pyinstaller 的目录中,这对我有效。

1
anaconda3未找到。 - David

2
我找到了如何解决这个错误的方法:
C:\Users\username>pyinstaller
'pyinstaller' is not recognized as an internal or external command,
operable program or batch file.

我们需要在cmd中输入以下代码:pip install pyinstaller 如果这不起作用,您应该进入 C:/user/pc name/Appdata(Appdata文件夹是隐藏的)/python 现在您应该复制脚本文件夹和C:/program files/python39 并将站点包复制到C:/program files/python39/lib 然后,如果您在cmd中键入pyinstaller,您将看到它起作用了。

2

奇怪的是,对我来说改变大小写解决了问题。我输入了python -m [脚本名称] [参数]。在[脚本名称]中,我输入了PyInstaller而不是pyinstaller,它实际上起作用了。我尝试了多次两种方式。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接