编辑:我可以使用哪些工具来查看可执行文件在尝试访问psycopg2软件包时尝试查找的软件包/文件?也许这有助于描述出现问题的地方。
我有一个python脚本在使用解释器运行时运行得非常好但是当我冻结它时,我收到错误:
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgresql.psycopg2
因为它通过解释器运行良好并且在冻结时失败,我怀疑我的setup.py文件出了问题。
#-*- coding: 'utf-8' -*-
from cx_Freeze import setup, Executable
import sys
# Dependencies are automatically detected, but it might need
# fine tuning.
# execute this file with the command: python setup.py build
buildOptions = dict(packages = ['ht_cg.ht_cg_objects'],
includes = ['ht_cg.ht_cg_objects'],
excludes = ['tkinter', 'PyQt4', 'matplotlib', 'tcl', 'scipy'],
include_files = ['./cg_source_prep/readme.txt', "./ht_cg_objects/ht_db_config.cfg"],
build_exe = 'build/source_density_exe')
sys.path.append('./')
sys.path.append('../')
executables = [
Executable(script = "cg_source_save.py",
initScript = None,
base='Console',
targetName = 'source_density_save.exe',
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
shortcutName="CG Source Density",
shortcutDir='DesktopFolder',
icon = "./cg_source_prep/archimedes.ico"
)
]
setup(name='Source_Density',
version = '1.0',
description = 'Source Density Uploader',
author = 'zeppelin_d',
author_email = 'zeppelin_d@email',
options = dict(build_exe = buildOptions),
executables = executables)
我正在读取base64编码的ht_db_config.cfg文件中的连接字符串,但是在尝试sqlalchemy.create_engine()之前打印出字符串并且它是正确的。我还添加了一个字符串文字作为sqlalchemy.create_engine方法的参数,并且冻结的可执行文件失败。失败的脚本的实际输出是:
postgresql+psycopg2://user_name:password@10.121.123.10:5432/ht_cg_prod
我已经替换了用户名和密码。
我一直想把这个问题解决几天。我很感激任何帮助。我正在运行python 3.4,sqlalchemy 1.0.8,cx_freeze 4.3.4和psycopg2 2.6,这是由' conda list'在Windows 8.1上。感谢。
答案 0 :(得分:3)
我终于找到了答案。在cx_freeze mailing list其他人遇到了同样的问题。解决方案是添加
'sqlalchemy.dialects.postgresql'
到我的cx_freeze构建选项中的包列表。