[英]Errors converting .py to .exe with pyinstaller (pyinstaller: command not found, mac)
我是 python 的新手,正在嘗試將我編寫的簡單 python 應用程序轉換為 a.exe。 我安裝了pyinstaller:
pip install pyinstaller
然后使用cd
導航到我的文件所在的文件夾。 這樣做之后,我就跑了
pyinstaller 'filename.py'
並得到這個錯誤:
-bash:pyinstaller:找不到命令
我怎樣才能解決這個問題?
“我從你的問題中推斷出你正試圖在 Mac 上運行 pyinstaller,而不是在 windows 上。如果是,那么當我遇到同樣的情況時,這對我有用”
First Remember :
If you are working on Mac, then your standalone file generated will not have .exe extension, rather it would be .app
看起來您正確安裝了 pyinstaller,但它不在您的 bash “PATH” 中,其中 bash 正常查找以運行任何已安裝的程序。
要檢查 pyinstaller 的安裝位置,請在終端中運行此命令
me:~ user$ sudo find pyinstaller ~/ | grep pyinstaller
這是我在 Mac 上看到的 output
/Users/user//Library/Python/2.7/bin/pyinstaller
現在讓我們像這樣將其添加到 PATH
me:~ user$ sudo nano /etc/paths (you can use vi instead of nano if you wish to)
這是樣本 output 我看到了(你的可能有點不同)
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
go 到最后一個空行並在那里輸入 ~/Library/Python/2.7/bin
your file should now look like this
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
~/Library/Python/2.7/bin
保存這個編輯過的文件並退出終端。
我:~ user$ pyinstaller
sage: 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 {all,imports,bootloader,noarchive}] [-s]
[--noupx] [--upx-exclude FILE] [-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]
[--runtime-tmpdir PATH] [--bootloader-ignore-signals]
[--distpath DIR] [--workpath WORKPATH] [-y]
[--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
scriptname [scriptname ...]
pyinstaller: error: too few arguments
只需運行此命令即可為 macOS 創建獨立程序。 它的名稱將與您的.py 文件名相同
me:~ user$ pyinstaller --windowed --onefile filename.py
if you want a different name for your standalone program then use following command
me:~ user$ pyinstaller --windowed --onefile --name myapp filename.py
if you want to add custom icon to your newly created standalone program then use following command
(before running this command make sure your icon flies in the same directory as your .py file)
me:~ user$ pyinstaller --windowed --onefile --icon "custom_icon.icns" --name myapp filename.py
如果你沒有得到以上任何一個為你工作然后嘗試在這樣的命令中給出 pyinstaller 的完整路徑
me:~ user$ /Users/user//Library/Python/2.7/bin/pyinstaller --windowed --onefile filename.py
要么
me:~ user$ ~/Library/Python/2.7/bin/pyinstaller --windowed --onefile filename.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.