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

时间:2015-08-25 13:08:09

标签: python flask py2exe setup.py software-distribution

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

我有模块,当没有从.exe

执行时,网站工作正常,没有ImportError

我在包装和交付方面相当新,并且不确定导致中断的设置是什么问题。来自> .exe转换。

Setup.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位。

修改:构建cmd = python setup.py py2exe

2 个答案:

答案 0 :(得分:1)

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

使用Setup.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
)

答案 1 :(得分:0)

我会将我的文件转换为EXE并通过主机进行部署。只需获取“自动Py To Exe”应用程序即可。在本地下载。打开应用程序,插入您的项目位置,如果需要,请进行一些设置,然后单击“转换”。妳去EXE格式的烧瓶。无需Python解释器即可在您喜欢的任何位置插入插件。