Python读取Oracle路径

发布于 2024-07-06 07:31:47 字数 495 浏览 7 评论 0 原文

在我的桌面上,我编写了一个连接到 Oracle 的小型 Pylons 应用程序。 我现在正尝试将其部署到运行 Win2k3 x64 的服务器上。 (我的桌面是32位XP)服务器上的Oracle安装也是64位的。

我在加载 OCI dll 时遇到错误,因此我将 32 位客户端安装到 C:\oracle32 中。

如果我将其添加到 PATH 环境变量中,效果会很好。 但我也想将 Pylons 应用程序作为服务运行 (使用此配方)并且不想将此 32 位库放在所有其他应用程序的路径上。

我尝试使用 sys.path.append("C:\\oracle32\\bin") 但这似乎不起作用。

On my desktop I have written a small Pylons app that connects to Oracle. I'm now trying to deploy it to my server which is running Win2k3 x64. (My desktop is 32-bit XP) The Oracle installation on the server is also 64-bit.

I was getting errors about loading the OCI dll, so I installed the 32 bit client into C:\oracle32.

If I add this to the PATH environment variable, it works great. But I also want to run the Pylons app as a service (using this recipe) and don't want to put this 32-bit library on the path for all other applications.

I tried using sys.path.append("C:\\oracle32\\bin") but that doesn't seem to work.

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

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

发布评论

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

评论(3

对岸观火 2024-07-13 07:31:47

sys.path 是Python PYTHONPATH 的内部表示,在我看来你想修改PATH。

我不确定这是否有效,但你可以尝试:

import os
os.environ['PATH'] += os.pathsep + "C:\\oracle32\\bin"

sys.path is python's internal representation of the PYTHONPATH, it sounds to me like you want to modify the PATH.

I'm not sure that this will work, but you can try:

import os
os.environ['PATH'] += os.pathsep + "C:\\oracle32\\bin"
≈。彩虹 2024-07-13 07:31:47

在执行 python.exe 之前,您需要将 c:\Oracle32\bin 目录附加到环境的 PATH 变量中。
在 Linux 中,出于类似的原因,我需要设置 LD_LIBRARY_PATH 变量,以便在调用 python 之前找到 Oracle 库。 我使用包装 shell 脚本来设置变量,然后调用 Python。
对于您的情况,也许您可​​以在服务启动时调用 .cmd 或 .vbs 脚本来设置 PATH 变量,然后使用 .py 脚本调用 python.exe。

我希望这有帮助!

You need to append the c:\Oracle32\bin directory to the PATH variable of your environment before you execute python.exe.
In Linux, I need to set up the LD_LIBRARY_PATH variable for similar reasons, to locate the Oracle libraries, before calling python. I use wrapper shell scripts that set the variable and then call Python.
In your case, maybe you can call, in the service startup, a .cmd or .vbs script that sets the PATH variable and then calls python.exe with your .py script.

I hope this helps!

触ぅ动初心 2024-07-13 07:31:47

如果您的 Python 应用程序在 64 位空间中运行,您将需要访问 Oracle oci.dll 的 64 位安装,而不是 32 位版本。 通常,您会在运行脚本之前更新系统路径以包含适当的 Oracle Home bin 目录。 该解决方案也可能会有所不同,具体取决于您使用什么组件从 Python 访问 Oracle。

If your Python application runs in the 64-bit space, you will need to access a 64-bit installation of Oracle's oci.dll, rather than the 32-bit version. Normally you would update the system path to include the appropriate Oracle Home bin directory, prior to running the script. The solution may also vary depending on what component you are using to access Oracle from Python.

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