Compile cx_Oracle for Maya & Python

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.

  1. Download the cx_Oracle source code from hereDirect link to the package I used (5.1.2)
  2. Unzip so that you have the following path (C:/cx_Oracle-5.1.2)
  3. I have the 64 bit Oracle SQL Developer Client installed to this path: C:/oracle/product/11.2.0/client_64bit
  4. I have 64 bit Python 2.7 installed here: C:/Program Files/Python27
  5. Download Oracle SDK for instant client from here I used. ( –
  6. Unzip the SDK anywhere (Example C:/OracleSDK)
  7. Create a folder inside your Oracle Client install called sdk. (Path in my case C:/oracle/product/11.2.0/client_64bit/sdk)
  8. 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.
  9. Create a folder inside your Oracle Client install called oci/include. (Path in my case C:/oracle/product/11.2.0/client_64bit/oci/include)
  10. 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
  11. 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
  12. 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)
  13. Run the following commands:

  1. You will now have a C:/cx_Oracle-5.1.2/build/
  2. 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-packages.
  3. 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

About the Author

Christian Akesson

Facebook Twitter Google+

Senior Technical Artist at Daybreak Games. Maya user since beta 1 in 1999.