不能运行其他机器上的app exe,python2.7,fpdf,pyinstaller
Can't run app exe on other machines, python2.7, fpdf, pyinstaller
我在其他机器上使用来自 pyinstaller 的 运行 exe 应用程序时遇到问题。它正在 PC 上寻找路径,我在其中构建了应用程序:
console output
我通过以下方式在 pyPDF 中使用和添加字体:
from fpdf import FPDF
pwd = os.path.realpath(os.path.dirname(sys.argv[0])) + "\font\DejaVuSansCondensed.ttf"
pdf = FPDF(orientation = 'L', unit = 'mm', format='A4')
pdf.add_page()
# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu', '', pwd, uni=True)
pdf.set_font('DejaVu', '', 18)
#then I use pdf.write() to write data
#save and close pdf file
pdf.output('C:\Users\' + getpass.getuser() + '\Documents\pdf_file' + time_stamp + '.pdf', 'F')
我尝试通过以下方式构建它:
pyinstaller app.py
pyinstaller --onefile app.py
在我构建代码的机器上没有问题。我想 fpdf 的输出方法或 pyinstaller 的设置中有一些东西,对吗?
我必须用 unicode 字符创建 pdf。我使用最新版本的 fpdf 和 pyinstaller 模块。
如有任何帮助,我将不胜感激。
提前谢谢你,
当你在你的机器上构建它时没有问题,因为你有 DejaVuSansCondensed.ttf
python 期望它的地方。但是,当您使用 PyInstaller 编译并在另一个系统上 运行 它时,它会在同一位置查找(在其他系统上可能不存在)。
我建议将该 ttf 文件复制到您当前的工作目录并将行字体行更新为(或适合您的代码的类似内容):
pwd = "DejaVuSansCondensed.ttf"
您还必须确保 .exe 可以独立于系统(相对于 exe)访问该文件。所以你必须将 ttf 文件复制到与你的 exe 相同的目录,这样当你 运行 它在另一台计算机上时,你的代码将在 exe 所在的目录中查找并找到 ttf 文件。
我在其他机器上使用来自 pyinstaller 的 运行 exe 应用程序时遇到问题。它正在 PC 上寻找路径,我在其中构建了应用程序:
console output
我通过以下方式在 pyPDF 中使用和添加字体:
from fpdf import FPDF
pwd = os.path.realpath(os.path.dirname(sys.argv[0])) + "\font\DejaVuSansCondensed.ttf"
pdf = FPDF(orientation = 'L', unit = 'mm', format='A4')
pdf.add_page()
# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu', '', pwd, uni=True)
pdf.set_font('DejaVu', '', 18)
#then I use pdf.write() to write data
#save and close pdf file
pdf.output('C:\Users\' + getpass.getuser() + '\Documents\pdf_file' + time_stamp + '.pdf', 'F')
我尝试通过以下方式构建它:
pyinstaller app.py
pyinstaller --onefile app.py
在我构建代码的机器上没有问题。我想 fpdf 的输出方法或 pyinstaller 的设置中有一些东西,对吗?
我必须用 unicode 字符创建 pdf。我使用最新版本的 fpdf 和 pyinstaller 模块。
如有任何帮助,我将不胜感激。
提前谢谢你,
当你在你的机器上构建它时没有问题,因为你有 DejaVuSansCondensed.ttf
python 期望它的地方。但是,当您使用 PyInstaller 编译并在另一个系统上 运行 它时,它会在同一位置查找(在其他系统上可能不存在)。
我建议将该 ttf 文件复制到您当前的工作目录并将行字体行更新为(或适合您的代码的类似内容):
pwd = "DejaVuSansCondensed.ttf"
您还必须确保 .exe 可以独立于系统(相对于 exe)访问该文件。所以你必须将 ttf 文件复制到与你的 exe 相同的目录,这样当你 运行 它在另一台计算机上时,你的代码将在 exe 所在的目录中查找并找到 ttf 文件。