我正试图为我的桌面应用程序生成一个exe。我用的是英语和阿拉伯语,使用的是自由的字体。当我试着安装自由式字体时-
inv_file = FPDF()
inv_file.add_page()
inv_file.set_xy(0, 0)
inv_file.add_font("monaco", "", os.path.join(gv.install_path,"FreeSerif.ttf"), uni=True)它完美地工作在我的桌面上。但是在生成一个exe之后,它会给我一个错误消息,在我的日志中没有目录中的搜索文件。我已经生成了一个自定义日志文件来查看问题所在。我已经看到,每当系统调用os.path.join时,它都试图访问本地机器目录,而不是客户端的安装目录。为了更好地理解,我共享了日志文件的屏幕截图。我也分享了我的setup_path代码-
gv.application_dir = "application"
gv.install_dir = os.path.join("application", "install")
gv.modules_dir = os.path.join("application", "modules")
gv.fi_dir = os.path.join("application", "icons")
gv.itemmanage_dir = os.path.join("application", "modules", "itemmanage")
gv.assets_dir = os.path.join("application", "modules", "itemmanage", "assets")
gv.image_dir = os.path.join("application", "modules", "itemmanage", "assets", "images")
gv.user_image_dir = os.path.join("application", "modules", "itemmanage", "assets", "images", "user")
gv.depend_dir = os.path.join("application", "modules", "dependancy")
gv.depend_image_dir = os.path.join("application", "modules", "dependancy", "images")
gv.invoice_dir = os.path.join("application", "modules", "invoices")发布于 2022-08-04 04:58:53
使用__file__。
在任何情况下,脚本都有所有的文件路径分配(只要文件路径实际上相对于该脚本):
使用os
import os
root = os.path.dirname(__file__)
gv.application_dir = os.path.join(root, "application")
gv.install_dir = os.path.join(gv.application_dir, "install")
...使用pathlib
from pathlib import Path
root = Path(__file__).parent.resolve()
gv.application_dir = root / 'application'
gv.install_dir = gv.application_dir / 'install'
...https://stackoverflow.com/questions/73230007
复制相似问题