Pyinstller打包exe报错解决

前言

  • 用python写了个自动化工具,为了方便没有python环境的同事使用,故准备将其打包成exe。
  • 由于本人使用的是虚拟环境,原来在默认的虚拟环境下没有pyinstaller,且写代码的电脑没有网络,因此只能本地安装包。

安装

  • 之前的项目是python2.7,安装pyinstaller时,需要安装各种依赖库,如下:
    - altgraph
    - dis3
    - future
    - macholib
    - pefile
    - pywin32-ctypes
  • 其中dis3和future都是因为python2的缘故,需要导入部分python3的特征。而通过阅读pyinstaller文档得知,pyinstaller3.4已经完全停止对pywin32的依赖,转而依赖pywin32-ctype。

问题

成功打包后,文件报错
Traceback (most recent call last): File “PyInstaller/loader/rthooks/pyi_rth__tkinter.py”, line 28, in <module> FileNotFoundError: Tcl data directory “/var/folders/nl/2wxh3z313l129zpzq2f8ww5m0000gn/T/_MEILUmJRc/tcl” not found. [2195] Failed to execute script pyi_rth__tkinter

一开始以为是虚拟环境的问题,排查了好久。
最后通过查阅各种外网得知,原因如下:

The Error Message basically refers to a file that cannot be found. In most cases, this file may not be necessary to run your application.
The only way to know it is to refer to the file pyi_rth_tkinter.py

The file pyi_rth_tkinter.py can be found under the venv folder of your
project.

venv/lib/python3.7/site-packages/PyInstaller/loader/rthooks/pyi_rth_tkinter.py

You will find a simple IF Statement that returns an error if a
specific file is not found in the tk or tcl directory. You can comment
the IF Statement as provided below and try running your PyInstaller
code once again

注释掉这几行代码(很神奇的解决方式。)

#if not os.path.isdir(tcldir):
    #raise FileNotFoundError('Tcl data directory "%s" not found.' % (tcldir))
#if not os.path.isdir(tkdir):
    #raise FileNotFoundError('Tk data directory "%s" not found.' % (tkdir))

最终生成的exe成功执行~

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值