运行时使用psycopg2 cx_Freeze exe导致sqlalchemy.exc.NoSuchmoduleError

时间:2015-08-28 18:27:59

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

编辑:我可以使用哪些工具来查看可执行文件在尝试访问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而没有运气。
  7. 我正在读取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上。感谢。

1 个答案:

答案 0 :(得分:3)

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

相关问题