【问题标题】:cx_Freeze exe results in sqlalchemy.exc.NoSuchmoduleError with psycopg2 at run timecx_Freeze exe 在运行时导致 sqlalchemy.exc.NoSuchmoduleError 与 psycopg2
【发布时间】:2015-11-23 12:00:15
【问题描述】:

编辑:我可以使用哪些工具来查看可执行文件在尝试访问 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)
  1. 我已尝试将“psycopg2”添加到包含列表和软件包列表中。
  2. 我已经安装了psycopg2 binary installer
  3. 我已确定“psycopg2”不在包含或软件包列表中。
  4. 我已安装 MS Visual C++ 2008 可再发行 x64 和 x86 软件包。
  5. Mike Bayer says a similar error is due to the connection string not being what I think it is 但我在创建引擎之前打印了我的 conn 字符串,它是正确的。它只有在冻结时才会损坏,否则相同的连接字符串可以正常工作。
  6. 我有另一个可以正常运行的冻结脚本。这两个脚本使用相同的方法从 sqlalchemy 创建引擎和元数据对象。我尝试将 psycopg2 文件从工作的可执行文件夹复制到损坏的文件夹,但没有任何结果。我尝试过复制随机 dll,但没有成功。

我正在从 ht_db_config.cfg 文件中读取连接字符串,该文件是 base64 编码的,但我在尝试 sqlalchemy.create_engine() 之前打印出该字符串,它是正确的。我还添加了一个字符串文字作为 sqlalchemy.create_engine 方法的参数,并且冻结的可执行文件失败。失败的脚本的实际输出是:

postgresql+psycopg2://user_name:password@10.121.123.10:5432/ht_cg_prod

我已经替换了用户名和密码。

这几天我一直在努力解决这个问题。我会很感激任何帮助。我正在运行由 Windows 8.1 上的“conda list”确定的 python 3.4、sqlalchemy 1.0.8、cx_freeze 4.3.4 和 psycopg2 2.6。谢谢。

【问题讨论】:

    标签: python sqlalchemy python-3.4 psycopg2 cx-freeze


    【解决方案1】:

    我终于找到了答案。在cx_freeze mailing list 上,其他人也遇到了同样的问题。解决方案是添加 'sqlalchemy.dialects.postgresql' 到我的 cx_freeze 构建选项中的包列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 2017-10-12
      相关资源
      最近更新 更多