将cx_Oracle部署到各个版本的Oracle客户端上

发布于 2024-09-11 12:15:46 字数 599 浏览 5 评论 0原文

我有一些小型 python 应用程序,它们使用 cx_Oracle 连接到 Oracle 数据库。我通过使用 py2exe 编译这些应用程序来部署它们,这在许多情况下都可以正常工作。

问题是,对于需要安装此版本的许多人来说,没有标准的 Oracle 客户端版本(例如 9i 和 10g),并且尝试让每个人都标准化单个 Oracle 客户端版本将非常令人沮丧。目前,我正在将 9.2 客户端与 cx_Oracle 4.4.1 用于 9i,因此当我 py2exe 时,生成的 exe 包含 cx_Oracle 4.4.1 库,并且无法与 10g 客户端一起使用。

我不使用任何 Oracle 版本的任何特定功能,因此除了 cx_Oracle 兼容性问题之外,我确实没有理由关心正在使用的客户端版本。

理想的解决方案是以某种方式编译一个完全独立于计算机上安装的 Oracle 客户端的版本。

如果这是不可能的,我愿意为每个主要的 Oracle 版本(my_app_9i.exe、my_app_10g.exe 等)编译单独的 exe,但我无法找到一种简单的方法来做到这一点,因为安装新的 cx_Oracle 会覆盖我的旧版本中,每当我进行更改时,我都必须不断地来回交换库以编译其他版本。

欢迎任何建议或其他选择。

I have some small python apps that use cx_Oracle to connect to an Oracle database. I deploy these apps by compiling them with py2exe, which works fine in many cases.

The problem is, there is no standard Oracle Client version (9i and 10g for example) across the many people who need to install this, and it would be very frustrating to try to get everyone to standardize on a single Oracle Client version. I'm using the 9.2 client with cx_Oracle 4.4.1 for 9i at the moment, and so when I py2exe the resulting exe includes the cx_Oracle 4.4.1 library and will not work with 10g clients.

I don't use any specific features of any of the Oracle versions so there's really no reason for me to care what client version is being used, except for the cx_Oracle compatibility issues.

The ideal solution would be to somehow compile a version that is completely independent of the Oracle Client installed on the machine.

If that's not possible, I would be willing to compile separate exes for each major Oracle version (my_app_9i.exe, my_app_10g.exe, etc) but I can't figure out an easy way to even do this since installing a new cx_Oracle overwrites my old version, I would have to keep swapping the library back and forth to compile the other versions whenever I make a change.

Any advice or other options are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-09-18 12:15:46

如果您想构建多个 cx_Oracle 版本(例如:cx_Oracle10g、cx_Oracle11g 等),那么您需要修改 cx_Oracle setup.py 脚本。脚本的最后一步是调用 setup();第一个参数是要构建的模块的名称。您所需要做的就是将 "cx_Oracle" 更改为 "cx_Oracle" + ver,其中 ver 为 10g11gsetup.py 添加另一个参数以动态选择它。

当然,一旦掌握了这一点,您就需要一种在运行时加载正确模块的机制。为此,您需要创建自己的 cx_Oracle 模块,该模块具有一个 __init__.py 文件,如下所示:

try:
  from cx_Oracle9g import *
except ImportError:
  try:
    from cx_Oracle10g import *
  except ImportError:
    try:
      from cx_Oracle11g import *

您所需要做的就是发送您的自定义 < code>cx_Oracle 模块加上正确的 cx_OracleXg 模块与您的应用程序。

或者,您可以让自定义 cx_Oracle 模块动态检查每个可用的 Oracle 客户端库(9g、10g、11g 等),然后仅导入正确匹配的 cx_OracleXg 模块。在这种情况下,您只需发送一个二进制文件,其中包含自定义 cx_Oracle 模块以及所有 cx_OracleXg 模块。

If you want to build multiple cx_Oracle versions (eg: cx_Oracle10g, cx_Oracle11g, etc.) then you'll need to modify the cx_Oracle setup.py script. The last step in the script is a call to setup(); the first parameter is the name of the module to build. All you need to do is to change "cx_Oracle" to "cx_Oracle" + ver, where ver is 10g, 11g, etc. Either create several scripts and hard-code it, or add another parameter to setup.py to select it dynamically.

Of course, once you've got that, you need a mechanism to load the correct module at runtime. To do that you'll want to create your own cx_Oracle module that has a __init__.py file that looks something like this:

try:
  from cx_Oracle9g import *
except ImportError:
  try:
    from cx_Oracle10g import *
  except ImportError:
    try:
      from cx_Oracle11g import *

All you need to do is ship your custom cx_Oracle module plus the correct cx_OracleXg module with your application.

Alternately, you could have your custom cx_Oracle module dynamically check for each available Oracle client library (9g, 10g, 11g, etc) and then only import the correct matching cx_OracleXg module. In this case, you only have to ship a single binary, containing your custom cx_Oracle module plus all of the cx_OracleXg modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文