pyinstaller 打包exe运行错误 No module named 'pkg_resources.py2_warn'

pyinstaller 打包exe运行错误 No module named ‘pkg_resources.py2_warn’
背景:
使用pyinstaller打包好exe后,运行出现以下错误。在更新pip的python库前打包是可以正常运行的。

打包过程没有出现任何错误提示。环境python3.7.4 win64

Traceback (most recent call last):
File “site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py”, line 13, in

File “c:\program files\python37\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py”, line 623, in exec_module
exec(bytecode, module.dict)
File “site-packages\pkg_resources_init_.py”, line 86, in
ModuleNotFoundError: No module named ‘pkg_resources.py2_warn’
[3844] Failed to execute script pyi_rth_pkgres
解决方法:
我的方法是:找到 \Python37\Lib\site-packages\pkg_resources_init_.py,把86行 注释掉。重新打包即可。

import(‘pkg_resources.extern.packaging.version’)
import(‘pkg_resources.extern.packaging.specifiers’)
import(‘pkg_resources.extern.packaging.requirements’)
import(‘pkg_resources.extern.packaging.markers’)
#import(‘pkg_resources.py2_warn’)

metaclass = type

详细说明:
出现这种错误主要升级了pip里的python库导致的。所以按照网上说明,降级pip对应库即可。然而要配对py版本和库的版本很麻烦。而且牵一发而动全身。

我根据错误提示说明找到了该__init__.py文件。86行的意思是导入py2_warn。于是看了下该目录py2_warn.py文件.

#py2_warn.py
import sys
import warnings
import textwrap

msg = textwrap.dedent("""
You are running Setuptools on Python 2, which is no longer
supported and
>>> SETUPTOOLS WILL STOP WORKING <<<
in a subsequent release (no sooner than 2020-04-20).
Please ensure you are installing
Setuptools using pip 9.x or later or pin to setuptools<45
in your environment.
If you have done those things and are still encountering
this message, please comment in
https://github.com/pypa/setuptools/issues/1458
about the steps that led to this unsupported combination.
“”")

pre = “Setuptools will stop working on Python 2\n”

sys.version_info < (3,) and warnings.warn(pre + “" * 60 + msg + "” * 60)
逻辑大概是“python版本小于3,则提示警告“。这逻辑对运行根本没影响。注释掉在__init__.py的引用即可。

其实可以看下官网,按照作者所说,“【翻译】(这库)放弃了python2的支持,(调用)需要python3.5或以上的版本”。

至于为什么我明明python3.7还因导入这玩意儿报错就不知道了。大概pyinstaller为了兼容性干了什么东西把。

  • 10
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 15
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值