这个错误通常是由于 Pyinstaller 打包时没有正确处理 PlotlyJS 库的原因导致的。

以下是解决此问题的一些方法:

  1. 在打包时使用 --add-data 参数将 PlotlyJS 库添加到可执行文件中:
pyinstaller your_script.py --add-data 'path/to/plotlyjs/*;plotlyjs/'

这将会将 PlotlyJS 库添加到可执行文件的 plotlyjs/ 目录下。

  1. 在你的脚本中指定 PlotlyJS 库的位置:
import plotly.io as pio
pio.renderers.default = 'browser'
pio.renderers.default = pio.renderers['plotly_mimetype+notebook_connected']
pio.templates.default = "plotly_dark"
pio.templates.default = "plotly"
pio.templates.default = "seaborn"
pio.templates.default = "ggplot2"
pio.templates.default = "none"

import os
if not os.path.exists("plotlyjs"):
    pio.ensure_writable_plotly_dir()

这将会在你的脚本运行时检查 PlotlyJS 库是否存在,并自动创建它(如果不存在)。

  1. 尝试使用其他库来代替 PlotlyJS。

如果以上方法无法解决问题,你可以尝试使用其他库来代替 PlotlyJS。例如,你可以尝试使用 Matplotlib、Seaborn 或 Bokeh 来绘制你的图表。

PyInstaller 报错 'plotlyjs argument is not a valid URL or file path' 解决方法

原文地址: https://www.cveoy.top/t/topic/os7Z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录