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.– Woss
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?
– Igor Pompeo
What is the result of
pip show cx_Oracle
?– Woss
@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:
– Igor Pompeo
And the rest? More information appears than that.
– Woss
@Andersoncarloswoss I was editing
– Igor Pompeo
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.– Woss
Use
python3 -m pip install
to install all your libraries, so you will know exactly which version you will be in.– Woss
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
– Igor Pompeo
So I guess you can make it on your own
– Woss
@Was the command Andersoncarloswoss with python3 or python? and even after being in python37 folder I cannot run the code without the error continuing
– Igor Pompeo
Aren’t you running on a different virtualenv? Open your IDE console and install cx_oracle again
– Vitor Luis