views:

414

answers:

3

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.

+2  A: 

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"
Moe
r'C:\oracle32\bin' might avoid some escaping headaches.
William Keller
Yeah, I thought PYTHONPATH was Python specific. This answer worked perfectly. I just had to make sure the line was added before the model was initialized.
JohnLavoie
A: 

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!

Aurelio Martin
A: 

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.

JoshL