Ich habe eine Python-Anwendung, die als Windows-Executable gestartet werden soll. Ich benutze py2exe und pymssql 1.9.908.
Ich habe das folgende Build-Script verwendet, um die Anwendung zu generieren:
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'BGAgent'
old_version = '0.1'
ver = '0.1'
distDir = 'Dist' + name + ver
shutil.rmtree(distDir, True)
shutil.rmtree('Dist' + name + old_version, True)
os.mkdir(distDir)
##############
class Target(object):
""" Eine einfache Klasse, die Informationen über unsere ausführbare Datei enthält. """
def __init__(self, **kw):
""" Standard-Konstruktor. Aktualisieren Sie bei Bedarf."""
self.__dict__.update(kw)
# MySQLdb
#dst = os.path.join(distDir, "MySQLdb")
#copy_tree(MySQLdb.__path__[0], dst )
# pymssql
site_packages_dir = os.path.dirname(pymssql.__file__)
pymssql_files = []#'pymssql.py', 'pymssql.pyc', 'pymssql.pyo', '_mssql.pyd']
for eggInfo in glob.glob(os.path.join(site_packages_dir, '*mssql*')) :
pymssql_files.append(os.path.basename(eggInfo))
for fname in pymssql_files :
src = os.path.join(site_packages_dir, fname)
dst = os.path.join(distDir, fname)
if(os.path.isfile(src)) :
shutil.copy(src, dst)
else :
shutil.copytree(src, dst)
includes = ['MySQLdb', 'pymssql', 'OpenSSL']
excludes = ['run_w.exe'] #['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter']
packages = ['MySQLdb', 'pymssql', 'OpenSSL']
dll_excludes = []#['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll']
data_files = ['server.pem',
'config.ini',
'run.bat',
#os.path.join(os.path.split(pymssql.__file__)[0], 'ntwdblib.dll'),
]
icon_resources = []
bitmap_resources = []
other_resources = []
MyApp_Target = Target(
# was zu bauen
script = "run.py",
icon_resources = icon_resources,
bitmap_resources = bitmap_resources,
other_resources = other_resources,
dest_base = name,
version = ver,
company_name = "",
copyright = "",
name = name,
)
setup(
data_files = data_files,
options = {"py2exe": {"compressed": 0,
"optimize": 1,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 3,
"dist_dir": distDir,
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile = r'library.zip',
console = [],
windows = [MyApp_Target],
service = [],
com_server = [],
ctypes_com_server = []
)
Der Build funktioniert, aber ich habe einen Fehler, als ich versucht habe, die Anwendung zu starten:
File "pymssql.pyo", Zeile 12, in
File "pymssql.pyo", Zeile 10, in __load
File "_mssql.pxd", Zeile 10, in init pymssql (pymssql.c:7370)
ImportError: Kein Modul namens _mssql
Die Dateien _mssql.pyd und pymssql.pyd befinden sich im Ausführungsverzeichnis.
BS-Version Windows 7 Enterprice SP 1.