【问题标题】:py2exe and cx_Oracle failed loading cx_Oracle.pydpy2exe 和 cx_Oracle 未能加载 cx_Oracle.pyd
【发布时间】:2016-08-16 10:39:06
【问题描述】:

给定以下python程序

testconnect.py

from sqlalchemy.dialects import oracle
from sqlalchemy import create_engine

url = 'oracle+cx_oracle://user:password@oracle-rds-01.....amazonaws.com:1521/orcl'

e = create_engine(url)

e.connect()
print('Connected')

setup.py

setup(
  options={
    'py2exe': {
      'bundle_files': 1,
      'compressed': True,
      'dll_excludes': ['OCI.dll'],
      'includes':['cx_Oracle']
    }
  },
  console=["testconnect.py"],
  zipfile=None
)

我得到以下回溯

Traceback (most recent call last):
  File "testconnect.py", line 7, in <module>
    e = create_engine(url)
  File "c:\Python34\lib\site-packages\sqlalchemy\engine\__init__.py", line 386, in create_engine
    return strategy.create(*args, **kwargs)
  File "c:\Python34\lib\site-packages\sqlalchemy\engine\strategies.py", line 75, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "c:\Python34\lib\site-packages\sqlalchemy\dialects\oracle\cx_oracle.py", line 769, in dbapi
    import cx_Oracle
  File "c:\Python34\lib\site-packages\zipextimporter.py", line 109, in load_module
    self.get_data)
ImportError: MemoryLoadLibrary failed loading cx_Oracle.pyd: The specified module could not be found. (126)

我曾尝试在 setup.py 中使用“包含”,导入 cx_Oracle 但无济于事。

我尝试使用 bundle_files=3 并使用 'data_files=' 将 cx_Oracle.pyd 文件复制到 dist 目录中,但我仍然遇到同样的问题

我需要对我的 setup.py 进行哪些更改才能捕获 cx_Oracle.pyd 文件以便加载

更新:

问题是我使用的是在安装 cx_Oracle 和即时客户端之前打开的 cmd 控制台来使用 py2exe 构建 exe

我关闭控制台重新打开它,Windows 能够找到相应的文件

现在在我的 Windows 10 笔记本电脑(64 位)上运行正常

但是当我尝试将此 EXE 部署到我的客户端计算机(64 位 windows 2008)时,我仍然得到以下信息

D:\Milliman>testconnect.exe
Traceback (most recent call last):
  File "testconnect.py", line 1, in <module>
  File "c:\Python34\lib\site-packages\zipextimporter.py", line 109, in load_module
ImportError: MemoryLoadLibrary failed loading cx_Oracle.pyd: The specified module could not be found. (126)

提前感谢您的帮助 安迪

【问题讨论】:

    标签: python py2exe cx-oracle


    【解决方案1】:

    需要在目标计算机上安装 Oracle 即时客户端(或同等客户端)。没有它,cx_Oracle 将无法工作。它(可能)试图找到的 DLL 是 OCI.DLL。

    【讨论】:

      【解决方案2】:

      我终于知道是怎么回事了

      我们部署到的机器是 windows 2008 Server 64 Bit 但它上面有 Oracle 32 位客户端

      我正在尝试使用 Cx_Oracle 64 位部署 py2exe python 3.4 app 64 位 这是找到 32 位 OCI.dll 并且无法加载

      我的解决方案是将 64 位 Instant Client 打包到 data_files 中。 然后在我的应用中修改应用内的路径

      import os
      if os.path.exists('./instant_client'):
        pth = os.environ.get('path')
        pth = '{0};{1}'.format('./instant_client' ,pth)
        os.environ['path'] = pth
      

      这样我可以保证 cx_Oracle 会找到正确的 OCI.dll 而不会干扰全局路径和该机器上已经安装的 oracle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-01
        • 1970-01-01
        相关资源
        最近更新 更多