通过cx\U冻结将Jinja2转换为exe不工作。北大资源问题

2024-04-25 05:23:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我的python windows应用程序正在使用jinja2,在通过qx_freeze冻结应用程序后,我发现jinja2函数出现错误。 从我的理解来看,jinja2正在尝试使用pkg_资源,在我冻结我的应用程序之前,它运行良好。这是我的setup.py文件:

import cx_Freeze
import sys
import os
import os.path
import re

# Dependence

base = None
if sys.platform == 'win32':
      base = 'Win32GUI'

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TLC_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

executables = [cx_Freeze.Executable('app.py',base='Win32GUI')]

cx_Freeze.setup(
      name="app",
      version="0.1",
      description="*********",
      executables= executables,
      options={'build_exe':{'packages':['tkinter','re','pandas','premailer','os','ttkthemes','jinja2','independentsoft'],
      'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
      ]
      }}
      )

这就是jinja2在冻结时失败的原因:

def __init__(self, package_name, package_path="templates", encoding="utf-8"):
    from pkg_resources import DefaultProvider
    from pkg_resources import get_provider
    from pkg_resources import ResourceManager

I don't know how to import pkg_resources into my .exe

Tags: installpathfromimport应用程序jinja2baseos