Python使用html解析包Requests-html运行py文件没问题,Pyinstaller打包exe后运行报错


背景

Python利用Requests-html查询百度排名,使用打包指令打包exe

PowerShell 全选
pyinstaller -F apiServer_paiming.py

遇到问题

打包后运行exe,出现报错,报错信息如下:

 Python Request-html模块打包exe后报错信息
PS E:\GZ\Python\gz\dist> .\apiServer_paiming.exe
Traceback (most recent call last):
  File "apiServer_paiming.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "run_baidu_paiming.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "requests_html.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "pyppeteer\__init__.py", line 43, in <module>
NameError: name '__version__' is not defined
[5884] Failed to execute script 'apiServer_paiming' due to unhandled exception!

分析问题

Python使用html解析包Requests-html运行py文件没问题,Pyinstaller打包exe后运行报错

apiServer_paiming.py 第14行信息

Python使用html解析包Requests-html运行py文件没问题,Pyinstaller打包exe后运行报错

run_baidu_paiming.py 中第七行信息

Python使用html解析包Requests-html运行py文件没问题,Pyinstaller打包exe后运行报错

通过错误信息,我们可以锁定问题是出在了requests-html中

查询资料

https://github.com/pyppeteer/pyppeteer/issues/213

https://github.com/pyppeteer/pyppeteer/issues/213#issuecomment-898283261

 

解决方案

打包exe的时候把打包指令改为:

PowerShell 全选
pyinstaller -F --onefile apiServer_paiming.py --copy-metadata pyppeteer

这种方式打包的exe就没有问题了

PowerShell 全选
PS E:\GZ\Python\gz\dist> .\apiServer_paiming.exe
 * Serving Flask app "apiServer_paiming" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5800/ (Press CTRL+C to quit)

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
管理员
上一篇:Python爬虫解析网页的提取html信息的常用方式
下一篇:百度搜索结果列表html元素分析
评论列表

发表评论

评论内容
昵称:
关联文章

Python使用html解析Requests-html运行py文件问题Pyinstaller打包exe运行
Python pyinstaller 打包参数说明
python3项目打包exe可执行程序
Python使用SQL Server数据库
Python使用selenium+chrome进行抓
VSCode无法格式化python代码py文件的解决办法
Python多线程中试用wmi
Python爬虫解析网页的提取html信息的常用方式
Python Windows服务
.net HTML解析工具HtmlAgilityPack使用
html发布到服务器部分jpg:net::ERR_BLOCKED_BY_CLIENT
Python读取excel xlrd读取xlsx:Excel xlsx file; not supported
YESWEB POS开发 Electron运行生成解决办法
.NETCore 运行项目:Could not load file or assembly ***
使用.NET 6开发TodoList应用(30)——实现Docker打包和部署
使用 mitmproxy + python 做拦截代理
vue打包js文件添加hash
Python windows服务: Installing service ALicense Error installing service: 拒绝访问
.net Core编译出现错误:指定的任务可执行文件“sgen.exe”未能运行,文件名或扩展名太长
python ChromeDriver下载地址

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码