首页 > 解决方案 > 从 pyinstaller python 冻结代码创建一个 pdf

问题描述

我想从 Python 创建一个 pdf 文件,其中包含 seaborn 绘图、图像和文本。在 jupyter notebook 中,行 :确实会导出图像和包含图像的 pdf 文件fig1.savefig("export-sns-plot.png")pdf.output("add_image.pdf")

但是,当我使用 Pyinstaller 冻结代码并启动 exe 时,没有任何反应,请帮助..

谢谢

# librairies import
import pandas as pd
from fpdf import FPDF
import seaborn as sns
sns.set()

#dataset import
outils1 = pd.read_csv("projet.csv")
#colums rename
df1 = outils1.rename(columns = {"Unnamed: 0": "Axes","Unnamed: 1":"Reponse"})

#plot generation
x1= df1.Axes
y1= df1.Reponse
sns_plot1 = sns.barplot(x1,y1,data=df1)

#save the plot
fig1 = sns_plot1.get_figure()
fig1.savefig("export-sns-plot.png")

pdf = FPDF(orientation = "L")

# Page 1
pdf.add_page()
pdf.image("export-sns-plot.png", x=10, y=20, w=100) # plot insert as a png file

# pdf generation     
pdf.output("add_image.pdf")

标签: pythonpdffpdf

解决方案


查看 Pweave 库(此处的文档:http://mpastell.com/pweave/ 。我不确定这是你要找的东西,但是使用 pweave,你可以从 python 脚本或 ipython notebook 中创建一个带有绘图、文本和代码的 pdf。


推荐阅读