No module named 'cx_Oracle' - Python

Asked

Viewed 950 times

0

Everybody, good afternoon, everybody.

I am trying to make a connection to the oracle database, but when I run my script gives this error to No module named 'cx_Oracle'. But I have it installed on the machine and I’m using python 3.6. Does anyone know how to solve this?

import cx_Oracle
uid = "user"    # usuário
pwd = "pwd"   # senha
db = "(DESCRIPTION =    (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = UBR001001-125)(PORT = 1521)))(CONNECT_DATA=(SID=corps0)))  "  #string de conexão do Oracle, configurado no 
                # cliente Oracle, arquivo TNSNAMES.ORA

connection = cx_Oracle.connect(uid+"/"+pwd+"@"+db) #cria a conexão
cursor = connection.cursor() # cria um cursor

cursor.execute("SELECT * FROM TAB") # consulta sql
result = cursor.fetchone() # busca o resultado da consulta
if result == None:
    print ("Nenhum Resultado")
    exit
else:
    while result:
        print (result[0])
        result = cursor.fetchone()

cursor.close()
connection.close()

That’s the code I’m trying to execute. My cx_Oracle is version 7.0 and I already have the environment variable configured.

  • And are you running the right version of Python? How are you running the script and how did you install the module? It is quite common for people to install with pip install X, but the default version is different from the one used when running the script.

  • So, I used the code Pip install cx_Oracle, and I’m running through my IDLE. How so correct version? This library does not work in Python 3.6?

  • What is the result of pip show cx_Oracle?

  • @Andersoncarloswoss Name: cx_Oracle Version: 7.0.0 Summary: python interface to oracle home-page: https//oracle.github.io/python-cx_Oracle Author: Anthony Tuininga Author email: [email protected] License: bsd License Location: c: python27 lib site-required Packages Requires: --by:

  • And the rest? More information appears than that.

  • @Andersoncarloswoss I was editing

  • See? The installation site is c:\python27 indicating that you have installed the library in python 2.7, but it is running at 3.6, which does not have the library.

  • Use python3 -m pip install to install all your libraries, so you will know exactly which version you will be in.

  • I tried to run this now and gave this result: python3 is not recognized as an internal or external command, a operable program or a batch file. But I have the environment variable as 3.7

  • So I guess you can make it on your own

  • @Was the command Andersoncarloswoss with python3 or python? and even after being in python37 folder I cannot run the code without the error continuing

  • Aren’t you running on a different virtualenv? Open your IDE console and install cx_oracle again

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.