简体   繁体   English

如何将 cx_oracle 与 Pyinstaller 捆绑在一起

[英]How to bundle cx_oracle with Pyinstaller

My goal is to use Pyinstaller to bundle an exe file from a simple python script that uses Tkinter and cx_oracle to access a database.我的目标是使用 Pyinstaller 从一个使用 Tkinter 和 cx_oracle 访问数据库的简单 python 脚本中捆绑一个 exe 文件。 The python code is developed on a windows machine with Anaconda, cx_oracle package and oracle client installed. python代码是在安装了Anaconda、cx_oracle包和oracle客户端的windows机器上开发的。 Then I need to run the exe file in many target windows machines without oracle client or Python.然后我需要在许多没有oracle 客户端或 Python 的目标 Windows 机器上运行 exe 文件。

I am using Python 2.7 and Pyinstaller 3.1 on the development machine.我在开发机器上使用 Python 2.7 和 Pyinstaller 3.1。

I searched quite a while online but only found one tutorial on this: https://mail.python.org/pipermail/tutor/2014-December/103608.html我在网上搜索了一段时间,但只找到了一个教程: https : //mail.python.org/pipermail/tutor/2014-December/103608.html

I followed the same procedure and modified the spec file as below:我按照相同的步骤修改了规范文件,如下所示:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['mycode.py'],
             pathex=['C:\\Users\\myuser\\PycharmProjects\\mycode'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries + [('oraociei11.dll','D:\ProgramFiles\Anaconda2\oraociei11.dll','BINARY')],
          a.zipfiles,
          a.datas,
          name='mycode',
          debug=False,
          strip=False,
          upx=True,
          console=True )

the bundle worked.捆绑工作。 The code runs on the original machine with oracle client installed.代码在安装了 oracle 客户端的原始机器上运行。 But on a separate machine without oracle client, it failed to run, with the below error message:但是在没有 oracle 客户端的单独机器上,它无法运行,并显示以下错误消息:

Exception in Tkinter callback Traceback (most recent call last): File "lib-tk\\Tkinter.py", line 1537, in call File "", line 152, in login DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "The specified module could not be found". Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“lib-tk\\Tkinter.py”,第 1537 行,调用文件“”,第 152 行,登录数据库错误:DPI-1047:64 位 Oracle 客户端库不能被加载:“找不到指定的模块”。 See https://oracle.github.io/odpi/doc/installation.html#windows for help请参阅https://oracle.github.io/odpi/doc/installation.html#windows寻求帮助

Now I am very confused what are the required steps to safely bundle an exe from a python script with cx_oracle so that it can run on a windows machine without oracle client?现在我很困惑,将 python 脚本中的 exe 安全地与 cx_oracle 捆绑在一起,以便它可以在没有 oracle 客户端的 Windows 机器上运行,需要哪些步骤? Or do I "have to" install oracle client on the target machine?还是我“必须”在目标机器上安装 oracle 客户端?

I really hope to find a more detailed tutorial on bundling cx_oracle with pyinstaller than the old link I found above.我真的希望找到比我在上面找到的旧链接更详细的关于将 cx_oracle 与 pyinstaller 捆绑在一起的教程。

cx_Oracle requires an Oracle client. cx_Oracle 需要 Oracle 客户端。 You will need to install that on the target machine!需要安装在目标机器上! Note the link in the error message: https://oracle.github.io/odpi/doc/installation.html#windows .请注意错误消息中的链接: https://oracle.github.io/odpi/doc/installation.html#windows It should help you out with everything you need to do to get cx_Oracle working on the target machine.它应该可以帮助您完成让 cx_Oracle 在目标机器上工作所需的一切。

Thank you for posting this question.感谢您发布这个问题。 You are on the right path.你走在正确的道路上。 You are only missing other .dll files.您只缺少其他 .dll 文件。 You need to add all .dll files found in your Oracle instant client folder to the .spec file.您需要将在 Oracle 即时客户端文件夹中找到的所有 .dll 文件添加到 .spec 文件中。 See below for an example I did for instant client 19.10:有关我为即时客户端 19.10 所做的示例,请参见下面的示例:

a.binaries = a.binaries + [('oraociei19.dll','.\\instantclient_19_10\\oraociei19.dll','BINARY')] a.binaries = a.binaries + [('oraociei19.dll','.\\instantclient_19_10\\oraociei19.dll','BINARY')]

  • [('orannzsbb19.dll','.\\instantclient_19_10\\orannzsbb19.dll','BINARY')] [('orannzsbb19.dll','.\\instantclient_19_10\\orannzsbb19.dll','BINARY')]
  • [('oraocci19d.dll','.\\instantclient_19_10\\oraocci19d.dll','BINARY')] [('oraocci19d.dll','.\\instantclient_19_10\\oraocci19d.dll','BINARY')]
  • [('oraocci19.dll','.\\instantclient_19_10\\oraocci19.dll','BINARY')] [('oraocci19.dll','.\\instantclient_19_10\\oraocci19.dll','BINARY')]
  • [('oci.dll','.\\instantclient_19_10\\oci.dll','BINARY')] [('oci.dll','.\\instantclient_19_10\\oci.dll','BINARY')]
  • [('ocijdbc19.dll','.\\instantclient_19_10\\ocijdbc19.dll','BINARY')] [('ocijdbc19.dll','.\\instantclient_19_10\\ocijdbc19.dll','BINARY')]
  • [('ociw32.dll','.\\instantclient_19_10\\ociw32.dll','BINARY')] [('ociw32.dll','.\\instantclient_19_10\\ociw32.dll','BINARY')]
  • [('oramysql19.dll','.\\instantclient_19_10\\oramysql19.dll','BINARY')] [('oramysql19.dll','.\\instantclient_19_10\\oramysql19.dll','BINARY')]
  • [('oraons.dll','.\\instantclient_19_10\\oraons.dll','BINARY')] [('oraons.dll','.\\instantclient_19_10\\oraons.dll','BINARY')]
  • [('orasql19.dll','.\\instantclient_19_10\\orasql19.dll','BINARY')] [('orasql19.dll','.\\instantclient_19_10\\orasql19.dll','BINARY')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM