天天看點

Python插件cx_Oracle的安裝

隻需兩步。

1.去下載下傳個正确版本的exe檔案并安裝

點選這裡

并不需要如下做法

C:\Users\Tian\AppData\Local\Programs\Python\Python35\Scripts>pip install cx_Oracle
Collecting cx_Oracle
  Using cached cx_Oracle-5.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Tian\AppData\Local\Temp\pip-build-axe3mvs8\cx-Oracle\setup.py", line 190, in <module>
        raise DistutilsSetupError(message)
    distutils.errors.DistutilsSetupError: cannot locate Oracle include files in D:\oracle\instantclient_11_2\

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Tian\AppData\Local\Temp\pip-build-axe3mvs8\cx-Oracle\
           

2.安裝instant_client

點選這裡,下載下傳正确的版本。

Python插件cx_Oracle的安裝
Python插件cx_Oracle的安裝

把本檔案夾中所有的dll檔案複制到python的site-packages檔案夾下

可以解決如下問題:

>>> db = cx_Oracle.connect('test', 'test', '40.1.10.15:1521/tian')
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    db = cx_Oracle.connect('test', 'test', '40.1.10.15:1521/tian')
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
           

3.如下問題的原因是oci.dll版本不對所導緻的,請回到第二步重新下載下傳正确版本的instant_client:

>>> import cx_Oracle
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import cx_Oracle
ImportError: DLL load failed: %1 不是有效的 Win32 應用程式。
           

參考文檔:

http://blog.csdn.net/u013600225/article/details/51168607

http://frenchmay.iteye.com/blog/1060631