我正在尝试从功能齐全的 python 3.4 脚本制作一个 exe 程序,但我无法嵌入有关官方 mysql 连接器的依赖项。这是有问题的示例代码:
import mysql.connector
from settings import *
connLocal = mysql.connector.connect( host = DB_CRM_HOST,
user = DB_CRM_USER,
passwd = DB_CRM_PASS,
db = DB_CRM_DB )
cursorLocal = connLocal.cursor ()
sqlStr = "SELECT * FROM Users"
cursorLocal.execute( sqlStr)
for row in cursorLocal.fetchall():
print(row)
这是我的设置脚本:
'''script per il setup'''
import sys
from cx_Freeze import setup, Executable
EXCLUDES = ['_ssl', # Exclude _ssl
'pyreadline', 'difflib', 'doctest', 'locale',
'optparse', 'pickle', 'calendar'] # Exclude standard library
PACKAGES = []
INCLUDES = []
SCRIPT_NAME = "sync_crm2web.py"
EXE_NAME = "sync_crm2web.exe"
PRJ_NAME = "sync_crm2web"
VERSION = 1.0
AUTHOR = "Antonio"
DESCRIPTION = "Sincronizzazione crm sito internet"
BASE = "Console" #"Win32GUI"
#------------------------------------------------------------------------------
BUILD_EXE_OPTIONS = {"packages": PACKAGES,
"excludes": EXCLUDES,
"includes": INCLUDES,
"path": sys.path,
'append_script_to_exe':False,
'build_exe':"dist/bin",
'compressed':True,
'copy_dependent_files':True,
'create_shared_zip':True,
'include_in_shared_zip':True,
'optimize':2,}
EXE = Executable(script=SCRIPT_NAME,
base=BASE,
compress=True,
targetDir="dist",
targetName=EXE_NAME,
initScript=None,
copyDependentFiles=True,
appendScriptToExe=True,
appendScriptToLibrary=False,
)
setup(name=PRJ_NAME,
version=VERSION,
author=AUTHOR,
description=DESCRIPTION,
options={"build_exe": BUILD_EXE_OPTIONS},
executables=[EXE])
还尝试强制 PACKAGES = [], INCLUDES = [] 结合 mysql、mysql-connector、mysql.connector 似乎不起作用。
我总是得到:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "sync_crm2web.py", line 1, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2189, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2201, in _find_and_load_unlocked
ImportError: No module named 'mysql'
有人能帮我吗?完整的 cx_freeze 日志在这里http://pastebin.com/S3TMzAnB