python - How to fix "No such file or directory" occuring at exe using plotly
问题描述
I am trying to write a python software that uses plotly
. The script works well when I execute it with the console. Afterward, I created an exe file using Pyinstaller. But the execution of the exe fails with the error message
FileNotFoundError: No such file or directory "Path\To\PythonScript\plotly\package_data\plotly.min.js"
Here is some information about my system:
Operating system: Windows 10
Python 3.7.4
Plotly 3.10.0
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, plot
xValues = [1, 2, 3]
yValues1 = [5, 5, 5]
yValues2 = [7, 6, 7]
firstTrace = go.Scatter( x = xValues, y = yValues1, mode='lines+markers', name='first' )
secondTrace = go.Scatter( x = xValues, y = yValues2, mode='lines+markers', name='second' )
plottedData = [firstTrace, secondTrace]
plot( plottedData )
What should I do, so the exe runs without this error?
解决方案
通常,PyInstaller 不会处理所有模块依赖项,尤其是当它们使用附加文件时。您需要手动将它们提供给您的最终可执行文件。
所以对于plotly
,它使用一个名为 的目录package_data
,其中包含模板文件、js 文件等。所以你需要使用Tree
类将它添加到你的可执行文件中。编辑您生成的规范文件:
# -*- mode: python -*-
block_cipher = None
a = Analysis(
...
)
a.datas += Tree("<Python_Path>/Lib/site-packages/plotly/package_data/", "./plotly/package_data")
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
...
推荐阅读
- python - 根据列值从 df 访问一行
- python - 使用 OpenCV 的直线角度
- amazon-eks - 在清单文件中为 EKS 集群分配角色?
- java - 使用 bazel 版本 4.0.0 在 -Werror 时抑制 java 路径警告
- flutter - 在 Flutter Navigator 2 中,didPop 到底在做什么?
- oracle18c - Oracle Database 18c 安装需要永远安装在 Windows 10 上
- python-3.x - 在经过验证的 pandas 数据框列中显示具有 False 值的行
- python-3.x - 如果python中不满足条件,有没有办法返回输入?
- javascript - 谷歌工作区插件用户事件处理问题
- ion-range-slider - ionrangeslider:禁用拖动滑块。只想用于展示