Mac zsh: command not found: pyinstaller。[看这一篇就够了]

一、问题总结与解决方法。

1) pyinstaller版本问题

如果使用下面命令安装pyinstaller,默认将安装最新的pyinstaller。

pip install pyinstaller

但对于python2.7,最高只支持3.6,所以安装时使用 下面指令。

pip install pyinstaller==3.6

2) 安装后仍然显示command not found

原因:
在系统/bin路径下找不到pyinstaller的二进制可执行文件。
终端输入

echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
返回的是以冒号分割的系统环境路径,可以依次查看,发现而其中任何一个路径下都找不到pyinstaller这个二进制文件。

解决:

2.1) macOS Catalina(10.15) 之前系统。

终端输入

pip show pyinstaller

Name: PyInstaller
Version: 3.6
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.
Home-page: http://www.pyinstaller.org
Author: Giovanni Bajo, Hartmut Goebel, David Vierra, David Cortesi, Martin Zibricky
Author-email: [email protected]
License: GPL license with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones)
Location: /Users/alexw/Library/Python/2.7/lib/python/site-packages
Requires: setuptools, altgraph, macholib, dis3
Required-by:

标黄那一句复制下来,待会要用。
终端输入

sudo vi ~/.bash_profile 

按下esc,再按i,就可以进入编辑模式。
在文件中加入一句话

扫描二维码关注公众号,回复: 16035129 查看本文章

export PATH=${PATH}:/Users/alexw/Library/Python/2.7/bin
标黄这里填入上面标黄那一句。

按下ese,再按wq,就可以保存这个文件。
终端输入

source .bash_profile

至此,在这一个终端窗口就可以使用pyinstaller了。但是如果你的mac系统是macOS Catalina(10.15)以后,那重新打开一个终端窗口,你会发现还是command not found.

2.2) macOS Catalina(10.15) 之后系统需要添加的步骤。

首先做完上面所有步骤。
然后终端输入

sudo vi ~/.zshrc

跟上面修改.bash_profile一行的操作,添加一行:

source ~/.bash_profile

保存以后,终端输入

source ~/.zshrc

再次打开新的终端窗口,输入

pyinstaller -v

发现已经可以显示对应信息。

3) 终端输入pyinstaller后有提示信息,但打包时报错

使用pyinstaller打包脚本时,报错

AttributeError: ‘PyiModuleGraph’ object has no attribute ‘edgeData’

终端输入

pip install --upgrade altgraph

二、原因分析

关于bash和zsh的差异,查看官方文档:
https://support.apple.com/zh-cn/HT208050

太复杂的话,我不想写,你们也不想看。旺柴一句话带过 :
终端使用pyinstaller打包,其实就是去系统环境下寻找pyinstaller这个可执行二进制文件
但是python的环境变量是众所周知的难搞,导致遍历所有系统路径都找不到pyinstaller这个二进制文件。
上述所有步骤,都是在把pyinstaller所在的路径,添加到系统路径下面。

猜你喜欢

转载自blog.csdn.net/qq_41749924/article/details/129401943