Deploying cx_Oracle on Windows

I am trying to use the cx_Oracle module in python to access a remote database and insert or delete rows in tables. BTW I downloaded the oracle 11.1 instant client, as well as the odbc and sqlplus versions. I set the environment variables ORACLE_HOME and TNS_ADMIN to a directory. I have unpacked files and add this directory to the PATH variable. Since I googled, I think there should be some .ora files, but I cannot find them.

I can use sqlplus commands from the command line, but my main problem is that I cannot install and use cx_Oracle . I do not want to use command line scripts; I just want to use cx_Oracle as an API.

Can anyone give me a full explanation, I'm really stuck there. All documents in this area are vague. Regards.

EDIT 1:

I tried the source cx_Oracle package with the python setup.py install and python setup.py build --compiler=mingw32 . I am not getting oracle error again, but I am getting command 'gcc' failed error. I tried the MinGW compiler and edited the PATH environment variable to contain the MinGW installation directory (for example, C:\MinGW ); I also installed Microsoft Visual C ++ (versions 2005, 2008 and 2010); but i still get the error.

EDIT 2:

Since @ jpmc26 mentioned tnsnames.ora files, I decided to add that I tried to create the tnsnames.ora file as well as the sqlplus.ora file and put them in the C:\oracle\instant_client_11_1\network\admin ; but as the game progressed, I realized that if you use the cx_Oracle.connect(username, password, cx_Oracle.makedsn(ip, port, sid)) command, you can skip the .ora files. cx_Oracle.makedsn will make the structure itself.

+3
source share
2 answers

I tried many ways to finally solve the problem. Since I think I should write a comprehensive answer, I will write about the problems that I encountered and their solutions, respectively; hoping this can help others. I also changed the name of the question to a suitable one. Here's what I went through during the installation of the cx_Oracle module on Windows 7 - the 32-bit version (I think other versions of windows will have similar solutions, but I'm not sure):

  • I tried installing cx_Oracle using easy_install and I got the No oracle client installed error. I downloaded the oracle sdk basic client and oracle sdk instant client for windows from the official Oracle website and installed it using the following steps:

    Unzip the base oracle instant client into the directory C:\oracle\instant_client_11_1\ .

    Unzip the oracle sdk operational client and copy the sdk folder to the C:\oracle\instant_client_11_1\ , therefore, we have a directory like C:\oracle\instant_client_11_1\sdk\ .

    Add C:\oracle\instant_client_11_1\ to the end of the PATH environment variable.

    Add a new variable called ORACLE_HOME and set its value to C:\oracle\instant_client_11_1\ .

    Reboot the computer.

  • I tried installing cx_Oracle using easy_install again, and I got the command 'gcc' failed: no such file or directory error command 'gcc' failed: no such file or directory and in some cases unable to find vcvarsall.bat ; this was because I did not have a C ++ compiler, so I followed the following steps to solve it:

    Download Microsoft Visual C ++ and install it.

    Download MinGW and install it; Please note that you must install the GCC module.

    Add C:\MinGW\ and C:\MinGW\bin\ (which contains gcc.exe ) to the end of the PATH environment variable.

  • I tried installing cx_Oracle using easy_install again, and I got the command 'gcc' failed with exit status 1 error command 'gcc' failed with exit status 1 ; I tried this step to solve it:

    Open the file C:\Python27\Lib\distutils\ cygwincompiler.py and delete all –mno-cygwin entries in this file; this is because recent versions of GCC removed the –mno-cygwin option, and it should not be there.

  • I tried installing cx_Oracle using easy_install and it worked.

But while searching the Internet, I found a couple of tricks that might be useful:

  • If you get the no module named win32api error message, its because you didnt install the win32 python extension on your computer, you must download the pywin32 module from Source Forge and install it.

  • If you still fail, you can try the older version of cx_Oracle ; but keep in mind everything we talked about in the lines above. Here you can find all versions of cx_Oracle .

  • If you want to use sqlplus , you have to take a few more steps. To do this, search the Internet.

+6
source

You can try several pre-created binaries . Unfortunately, the installer is MSI, so installation using virtualenv not possible.

I assume that you are referencing the ora file - this is the TNS name file. If so, this is a text file with a specific format. This may help: http://www.orafaq.com/wiki/Tnsnames.ora . According to the FAQ , Oracle will look in the TNS_ADMIN directory for the tnsnames.ora file. Please note that the use of a TNS name file may be optional. In many cases, you can refuse what you usually put in the TNS name file (something like (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))) (CONNECT_DATA=(SERVICE_NAME=ORA11))) ) in the same place where you would get the name TNS.

Welcome to Oracle. Good luck. You will need this. (Yes, all of this is complicated by Oracle.)

+2
source

Source: https://habr.com/ru/post/1013708/


All Articles