鱼C论坛

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

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

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

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

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

x
各位大神求助!!!

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

代码如下:
import sys,os
from PySide2 import QtCore
from PySide2 import QtWidgets
from PySide2.QtGui import *
from PySide2.QtCore import *
from pyecharts.charts import Bar
from PySide2.QtWidgets import *
from pyecharts import options as opts
from PySide2.QtUiTools import QUiLoader
from pyecharts.globals import CurrentConfig
from PySide2.QtWebEngineWidgets import QWebEngineView

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

class Form(QWidget, Ui_Form):
    def __init__(self, parent = None):
        CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
##        # os.getcwd() 返回当前文件路径
        super(Form, self).__init__(parent) # 调用父类的方法
        self.setupUi(self)
        
        x = [ 'a1','b1','c1' ]
        y1 = [ 1240,524,270 ]
        y2 = [1300,300,530]
        bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
##        bar = Bar(init_opts=opts.InitOpts())
        bar.add_xaxis(xaxis_data=x)
        bar.add_yaxis(series_name='A',y_axis=y1)
        bar.add_yaxis(series_name='B',y_axis=y2)
        bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
        
        bro = QWebEngineView()
        html_path=os.getcwd()+'/'+'chart22.html'
        bar.render(html_path)
        bro.setUrl(QUrl(html_path.replace('\\','/')))
        self.scrollArea.setWidget(bro)
        print()
    
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    widget = Form()
    widget.show()
    sys.exit(app.exec_())

上面代码中的ui_14.py文件代码如下:
import sys,os
from PySide2 import QtCore
from PySide2 import QtWidgets
from PySide2.QtGui import *
from PySide2.QtCore import *
from pyecharts.charts import Bar
from PySide2.QtWidgets import *
from pyecharts import options as opts
from PySide2.QtUiTools import QUiLoader
from pyecharts.globals import CurrentConfig
from PySide2.QtWebEngineWidgets import QWebEngineView

from ui_14 import *

class Form(QWidget, Ui_Form):
    def __init__(self, parent = None):
        CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
##        # os.getcwd() 返回当前文件路径
        super(Form, self).__init__(parent) # 调用父类的方法
        self.setupUi(self)
        
        x = [ 'a1','b1','c1' ]
        y1 = [ 1240,524,270 ]
        y2 = [1300,300,530]
        bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
##        bar = Bar(init_opts=opts.InitOpts())
        bar.add_xaxis(xaxis_data=x)
        bar.add_yaxis(series_name='A',y_axis=y1)
        bar.add_yaxis(series_name='B',y_axis=y2)
        bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
        
        bro = QWebEngineView()
        html_path=os.getcwd()+'/'+'chart22.html'
        bar.render(html_path)
        bro.setUrl(QUrl(html_path.replace('\\','/')))
        self.scrollArea.setWidget(bro)
        print()
    
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    widget = Form()
    widget.show()
    sys.exit(app.exec_())

救救孩子吧!!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-2-24 20:25:03 | 显示全部楼层
这跟网络有什么关系吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

你可以试一下用pyinstaller打包,总是不成功。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-24 23:48:41 | 显示全部楼层
不成功有提示?
还是打包后运行没有达到正常效果?
想知道小甲鱼最近在做啥?请访问 -> 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

想知道小甲鱼最近在做啥?请访问 -> 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
这里找下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-6 08:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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