Python: import cx_Oracle ImportError: No module named cx_Oracle error is thown

后端 未结 8 1731
耶瑟儿~
耶瑟儿~ 2020-12-15 10:33

I try to write a script in .py for oracle connectivity:

#!/usr/bin/python

import cx_Oracle

connstr=\'username/pwd@database\'
conn = cx_Oracle.connect(conns         


        
相关标签:
8条回答
  • 2020-12-15 10:46

    Windows help:

    1. Get the instant client from here.
    2. Put the directory into your PATH variable.
    3. Go to the command prompt (Win+R and type cmd) and set 2 variables matching your location- for example:

      set TNS_ADMIN=C:\instant_client\instantclient_11_2 set ORACLE_HOME=C:\instant_client\instantclient_11_2

    Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.

    You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3

    0 讨论(0)
  • 2020-12-15 10:48

    Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install.

    pip install cx_oracle
    

    The above command installed cx_oracle=6.1 Please note that I'm using python 2.7.14 Anaconda release and oracle 12c.

    0 讨论(0)
  • 2020-12-15 10:48

    Windows and Anaconda help

    Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6

    Only workaround I could find was to change the root environment from 3.6 to 3.5:

    activate root
    conda update --all python=3.5
    

    When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.

    Tested it with import and worked fine.

    import CX_Oracle
    
    0 讨论(0)
  • 2020-12-15 10:49

    I had a similar problem, you gotta make sure you have:

    1. oracle instant client
    2. cx_Oracle binary( from SourceForge )
    3. Python IMPORTANT: Make sure they are ALL either 64-bit or 32-bit, mixing is gonna cause problems
    0 讨论(0)
  • 2020-12-15 10:52

    To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.

    0 讨论(0)
  • 2020-12-15 10:55

    Unknown92 answer helped me (on windows). Note that all versions must fit.

    I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with:

    • Python 3.5.1 64bit. for some reason the default download link from the main page is for the 32bit version.
    • And oracle instance client 12.1.0.2.0 (the file named instantclient-basic-windows.x64-12.1.0.2.0.zip) here.
    0 讨论(0)
提交回复
热议问题