I recently wanted to use cx_Oracle to connect to a database inside Maya. The problem is that cx_Oracle.pyd is compiled against an older version of Visual Studio than Maya is and that causes Maya to throw a dll error when you attempt to import cx_Oracle. The solution is to compile the source of cx_Oracle using Visual Studio 2010. The solution is also backwards compatible with vanilla Python 2.7.x.
Here are the steps I went through, followed by a link to the compiled pyd file.
- Download the cx_Oracle source code from here. Direct link to the package I used (5.1.2)
- Unzip so that you have the following path (C:/cx_Oracle-5.1.2)
- I have the 64 bit Oracle SQL Developer Client installed to this path: C:/oracle/product/11.2.0/
- I have 64 bit Python 2.7 installed here: C:/Program Files/Python27
- Download Oracle SDK for instant client from here I used. (18.104.22.168.0) – instantclient-sdk-windows.x64-
- Unzip the SDK anywhere (Example C:/OracleSDK)
- Create a folder inside your Oracle Client install called sdk. (Path in my case C:/oracle/product/11.2.0/
- Copy the C:/OracleSDK/include DIRECTORY to the C:/oracle/product/11.2.0/
client_64bit/sdk directory. You now have this path C:/oracle/product/11.2.0/ client_64bit/sdk/include, which contains a bunch of header files.
- Create a folder inside your Oracle Client install called oci/include. (Path in my case C:/oracle/product/11.2.0/
- Copy the contents of C:/OracleSDK/sdk/lib (2 directories) into C:/oracle/product/11.2.0/
client_64bit/oci/include directory. You now have this path C:/oracle/product/11.2.0/ client_64bit/oci/include/bc and C:/oracle/product/11.2.0/ client_64bit/oci/include/msvc
- Copy the lib files from C:/oracle/product/11.2.0/
client_64bit/oci/include/msvc into your Python’s libs directory. In my case to here – C:/Program Files/Python27/libs
- Open up a Visual Studio 2010 64 Command Prompt (Start -> All programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio x64 Win64 Command Prompt (2010)
- Run the following commands:
:: Commands to be run
set PATH=C:oracleproduct11.2.0client_64bit;C:Program FilesPython27;%PATH%
set PYTHONHOME=C:Program FilesPython27
python setup.py build
python setup.py install
- You will now have a C:/cx_Oracle-5.1.2/build/lib.
- To clean things up, I removed the lib files I copied to my Python install in step 9. I also removed the cx_Oracle.pyd from C:/Program Files/Python27/Lib/site-
- Put the cx_Oracle.pyd within your Python path, import cx_Oracle and connect to your data base. Happy DB-ing
...just want to bypass all this “fun”and download the cx_Oracle.pyd below.Download cx_Oracle.pyd
Spread the knowledge