Compiling cx_Oracle for Maya’s 64 bit Python in Windows 7 64 with Visual Studio 2010
I recently wanted to use cx_Oracle to connect to a database inside Maya. The problem is that cx_Oracle.pyd is compiled against Visual Studio 2008 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 Studion 2010. The solution is also backwards compatible with vanilla Python 2.7.x.
Here are the steps I went through:
- 1. Download the cx_Oracle source code from here. Direct 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/
- 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. (22.214.171.124.0) – instantclient-sdk-windows.x64-
- 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/
- 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/
- 8. 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
- 9. 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
- 10. 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)
- 11.Run the following commands:
SET VS90COMNTOOLS=%VS100COMNTOOLS% set ORACLE_HOME=C:\oracle\product\11.2.0\client_64bit set PATH=C:\oracle\product\11.2.0\client_64bit;C:\Program Files\Python27;%PATH% set PYTHONHOME=C:\Program Files\Python27 cd C:\cx_Oracle-5.1.2 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
If you just want to bypass all this “fun”, feel free to download the cx_Oracle.pyd from here .