python - 找不到来自 pyinstaller“spec”文件的“datas”数组中的文件
问题描述
通过创建以下规范文件:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
face_models = [
('face_recognition_models/models/*.dat', 'face_recognition_models/models')
]
a = Analysis(['main.py'],
pathex=[],
binaries=face_models,
datas=[
('material/haarcascade_frontalface_default.xml','tools'),
('processing/model_01_human_category.h5','tools'),
('icon/faceicon.ico','tools')
],
# MORE CODE...
我尝试运行创建的 .exe,但出现以下错误。
我的第 69 行:
self.model = load_model('tools/model_01_human_category.h5')
我承认我不知道还能做什么...
解决方案
我找到了一个解决问题的有趣解决方案,点击链接:https ://github.com/explosion/spaCy/issues/3592
我使用此脚本从 .spec 构建的文件中获取正确的 PATH
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath("__file__")))
return os.path.join(base_path, relative_path)
推荐阅读
- flutter - Flutter: How would I create calendar plugin?
- c# - 如何通过asp.net c#中的下拉列表获取最近3年的数据?
- android - 应用程序在 Play 商店中显示“您的设备与此版本不兼容”,但手动安装 apk 工作正常
- solr - Solr索引数据库中的大行
- c# - 从当前项目获取文件路径
- autodesk-forge - 翻译后更新模型中的单个元素
- sql - 如果真正运行查询,则检查时间
- php - 如何自定义结帐 woocommerce 字段?
- phpspreadsheet - phpspreadsheet 错误:消息:语法错误,意外'='
- linux - Knative 设置的确切系统要求是什么?为什么基本设置指南导致我资源枯竭?