pyinstaller 打成exe,遇到Failed to execute script 'first' due to unhandled exception:cannot import name问题.
Failed to execute script 'first' due to unhandled exception:cannot import name 'recordclient' from 'recordtool' (unknown location)

解决办法:
- 检查是否有
__init__.py
文件 - 检查是否添加系统环境变量 * PYTHONPATH *
PYTHONPATH是Python搜索路径,默认我们import的模块都会从PYTHONPATH里面寻找。

右击【我的电脑】-【属性】-【高级系统设置】-【环境变量】-【新建】,变量名写PYTHONPATH,变量值就是你要导入模块的路径了,以后还要导入其他模块,就继续在后面添加路径,至此,已经设置好了。
添加项目目录上一级目录 PYTHONPATH
G:\python 是项目的上级目录
再重新打包就可以了。
网友评论