我正在使用pyinstaller
来构建我的flask应用程序,
一切都很好,除了我在Jinja2模板上遇到问题。在
它给了我jinja2.exceptions.TemplateNotFound
我试图将from app import template
放在templates文件夹中,但是没有用(我想是因为它们不包含任何py
文件)。在
我还尝试更改.spec
文件以包含templates
文件夹
added_files = [
( '..\\CommerceApp\\app\\templates', 'templates' ),
( '..\\CommerceApp\\app\\static', 'static' )
]
a = Analysis(['..\\CommerceApp\\run.py'],
pathex=['D:\\PythonProjects\\CommerceAppExe'],
binaries=None,
datas=added_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
但它也不起作用,就像我自己手动复制文件夹一样。在
有没有办法把模板和.exe捆绑在一起?在
编辑
这是我的spec
文件
编辑2
接受的答案更改为^{
编辑3
我还意识到,我可以用我的包名创建一个新的文件夹,填充静态模板css
,html
,等等,它就可以工作了(类似于gmas80脚本的结果)
我不相信这个问题是https://stackoverflow.com/a/35816876/2741329中所描述的。我刚刚能够用
Jinja2
冻结一个应用程序。在在我的spec文件中,我使用以下方法收集所有模板:
然后将
pkg_data
添加到COLLECT
(1-文件夹)或EXE
(1文件).spec在单文件夹解决方案中,您应该能够在创建的子文件夹中找到所有模板。在
编辑
这可能有用(假设您有一个包(即,您有一个
^{pr2}$__init__.py
),遵循以下建议:http://flask.pocoo.org/docs/0.10/patterns/packages/):^{} 包使用了} API。} 包提供的。在
PyInstaller
不支持的^{pkg_resources
模块是通过^{从^{} 页,共^{} :
相关问题 更多 >
编程相关推荐