鱼C论坛

 找回密码
 立即注册
查看: 1828|回复: 5

如何在局域网下 用pyinstaller 打包 pyecharts 生成的文件 ?

[复制链接]
发表于 2022-2-24 20:08:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
各位大神求助!!!

本人想在局域网的环境下编一个pyecharts生成的应用。
但pyecharts生成的html文件都是基于浏览器打开的,
之前用"render_embed()",发现可以打包成功,但打开应用是空白。
之后尝试用“render()”,还是不能成功。
穷途末路,在此求教网络上的大神帮忙解决!

代码如下:
  1. import sys,os
  2. from PySide2 import QtCore
  3. from PySide2 import QtWidgets
  4. from PySide2.QtGui import *
  5. from PySide2.QtCore import *
  6. from pyecharts.charts import Bar
  7. from PySide2.QtWidgets import *
  8. from pyecharts import options as opts
  9. from PySide2.QtUiTools import QUiLoader
  10. from pyecharts.globals import CurrentConfig
  11. from PySide2.QtWebEngineWidgets import QWebEngineView

  12. from ui_14 import *  #Pyside2生成的py文件

  13. class Form(QWidget, Ui_Form):
  14.     def __init__(self, parent = None):
  15.         CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
  16. ##        # os.getcwd() 返回当前文件路径
  17.         super(Form, self).__init__(parent) # 调用父类的方法
  18.         self.setupUi(self)
  19.         
  20.         x = [ 'a1','b1','c1' ]
  21.         y1 = [ 1240,524,270 ]
  22.         y2 = [1300,300,530]
  23.         bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
  24. ##        bar = Bar(init_opts=opts.InitOpts())
  25.         bar.add_xaxis(xaxis_data=x)
  26.         bar.add_yaxis(series_name='A',y_axis=y1)
  27.         bar.add_yaxis(series_name='B',y_axis=y2)
  28.         bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
  29.         
  30.         bro = QWebEngineView()
  31.         html_path=os.getcwd()+'/'+'chart22.html'
  32.         bar.render(html_path)
  33.         bro.setUrl(QUrl(html_path.replace('\\','/')))
  34.         self.scrollArea.setWidget(bro)
  35.         print()
  36.    
  37. if __name__ == "__main__":
  38.     app = QtWidgets.QApplication(sys.argv)
  39.     widget = Form()
  40.     widget.show()
  41.     sys.exit(app.exec_())

复制代码


上面代码中的ui_14.py文件代码如下:
  1. import sys,os
  2. from PySide2 import QtCore
  3. from PySide2 import QtWidgets
  4. from PySide2.QtGui import *
  5. from PySide2.QtCore import *
  6. from pyecharts.charts import Bar
  7. from PySide2.QtWidgets import *
  8. from pyecharts import options as opts
  9. from PySide2.QtUiTools import QUiLoader
  10. from pyecharts.globals import CurrentConfig
  11. from PySide2.QtWebEngineWidgets import QWebEngineView

  12. from ui_14 import *

  13. class Form(QWidget, Ui_Form):
  14.     def __init__(self, parent = None):
  15.         CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
  16. ##        # os.getcwd() 返回当前文件路径
  17.         super(Form, self).__init__(parent) # 调用父类的方法
  18.         self.setupUi(self)
  19.         
  20.         x = [ 'a1','b1','c1' ]
  21.         y1 = [ 1240,524,270 ]
  22.         y2 = [1300,300,530]
  23.         bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
  24. ##        bar = Bar(init_opts=opts.InitOpts())
  25.         bar.add_xaxis(xaxis_data=x)
  26.         bar.add_yaxis(series_name='A',y_axis=y1)
  27.         bar.add_yaxis(series_name='B',y_axis=y2)
  28.         bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
  29.         
  30.         bro = QWebEngineView()
  31.         html_path=os.getcwd()+'/'+'chart22.html'
  32.         bar.render(html_path)
  33.         bro.setUrl(QUrl(html_path.replace('\\','/')))
  34.         self.scrollArea.setWidget(bro)
  35.         print()
  36.    
  37. if __name__ == "__main__":
  38.     app = QtWidgets.QApplication(sys.argv)
  39.     widget = Form()
  40.     widget.show()
  41.     sys.exit(app.exec_())

复制代码


救救孩子吧!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-2-24 20:25:03 | 显示全部楼层
这跟网络有什么关系吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-2-24 20:27:55 | 显示全部楼层
isdkz 发表于 2022-2-24 20:25
这跟网络有什么关系吗?

你可以试一下用pyinstaller打包,总是不成功。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-24 23:48:41 | 显示全部楼层
不成功有提示?
还是打包后运行没有达到正常效果?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-2-28 16:08:31 | 显示全部楼层
ba21 发表于 2022-2-24 23:48
不成功有提示?
还是打包后运行没有达到正常效果?

打包可以顺利打包,但是打开程序的时候报错

Failed to execute script '文件名' due to unhandled exception: simple_chart.html

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-28 18:36:29 | 显示全部楼层
拉格朗晶 发表于 2022-2-28 16:08
打包可以顺利打包,但是打开程序的时候报错

Failed to execute script '文件名' due to unhandled e ...

估计是打包前后路径问题 。
http://1118pc.com/show_pdetails.asp?id=1010
这里找下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-30 04:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表