Python Flask - 将服务器构建为可执行文件 (Py2exe)

标签 python flask py2exe setup.py software-distribution

我有一个 flask 项目,一切似乎都运行良好。当使用 py2exe 构建包时,(目标服务器是 Windows 服务器呃),可执行文件可以执行,但给我留下了 ImportError: No module named 'jinja2.ext'

我有这个模块,当不从 .exe 执行时,网站工作正常,没有 ImportError

我在打包和交付方面还很陌生,不确定导致 .py -> .exe 转换中断的设置有什么问题。

设置.py
from setuptools import setup, find_packages

import py2exe



NAME = "WorkgroupDashboard"
VERSION = "1.0"



setup(
    name=NAME,
    version=VERSION,
    description="Provides real time ISIS connection data",
    long_description="",
    # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[],
    author="Test User",
    author_email='',
    url='',
    license='Free',
    packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
    include_package_data=True,
    zip_safe=False,
    install_requires=[
        'flask >= 0.10.1',
        'SQLAlchemy>=0.6'
    ],
    console=['DashboardBack.py']
)

这个想法是为了打开服务器,只需执行.exe。服务器上不会有 python。我正在使用 Python 3.4 64 位。

编辑:build cmd = python setup.py py2exe

最佳答案

看来,设置命令进入 py2exe optuons=[]

工作设置.py

__author__ = ''


import sys
from glob import glob # glob will help us search for files based on their extension or filename.
from distutils.core import setup # distutils sends the data py2exe uses to know which file compile
import py2exe

data_files = []
setup(
    name='WorkgroupDashboard',
    console=['DashboardBack.py'], # 'windows' means it's a GUI, 'console' It's a console program, 'service' a Windows' service, 'com_server' is for a COM server
    # You can add more and py2exe will compile them separately.
    options={ # This is the list of options each module has, for example py2exe, but for example, PyQt or django could also contain specific options
        'py2exe': {
            'packages':['jinja2'],
            'dist_dir': 'dist/test', # The output folder
            'compressed': True, # If you want the program to be compressed to be as small as possible
            'includes':['os', 'logging', 'yaml', 'flask', 'sqlalchemy'], # All the modules you need to be included,  because py2exe guesses which modules are being used by the file we want to compile, but not the imports
        }
    },

    data_files=data_files # Finally, pass the
)

关于Python Flask - 将服务器构建为可执行文件 (Py2exe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32204887/

相关文章:

python - 使用 matplotlib 进行 PCA 的基本示例

python - 尝试了解 WSGI 的阻塞本质

python - 使用 WTForms 填充文本区域字段

python - "ImportError: DLL load failed"和 "No module named .."之间的区别

python - Py2Exe 生成日志文件

python - 将 Google Analytics API 库添加到 Google App Engine

python - 如何让 OpenGL 在 pygame 中绘制非显示表面?

python - 使用 Flask 测试客户端请求传递 cookie header

python - 无法使用 py2exe 作为 'Domain\ComputerName' pyodbc 登录

python - 将一列中的值替换为另一列的特定实例