Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

python - Deploying cx_Oracle in Windows

I'm trying to use cx_Oracle module in python to access a remote database and insert or delete rows in tables. BTW I have downloaded oracle instant client 11.1 and also odbc and sqlplus versions. I have set environment variables ORACLE_HOME and TNS_ADMIN to directory I have unzipped files there and add this this directory to the PATH variable. As I googled I think there should be some .ora files but I can't find them.

I can use sqlplus commands from command line, but my main problem is that I can't install and use cx_Oracle. I don't want to use any command line scripts; I just want to use cx_Oracle as an API.

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

EDIT 1:

I tried the source package of cx_Oracle with python setup.py install and python setup.py build --compiler=mingw32 commands. I don't get the oracle error again, but I'm getting command 'gcc' failed error. I tried MinGW compiler and have edited environment variable PATH to contain MinGW install directory(e.g. C:MinGW); I have also installed Microsoft Visual C++(versions 2005, 2008 and 2010); but I still get the error.

EDIT 2:

Since @jpmc26 mentioned about tnsnames.ora files, I decided to add that I have tried to make a tnsnames.ora and also a sqlplus.ora file and put them in directory C:oracleinstant_client_11_1 etworkadmin; but as I googled I realized that if you use cx_Oracle.connect(username, password, cx_Oracle.makedsn(ip, port, sid)) command, you can skip .ora files. cx_Oracle.makedsn would make the structure itself.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I tried a lot of ways to finally solve the problem. Since I think I should write a comprehensive answer, I will write the problems that I faced and their solutions respectively; hoping it can help others. I also changed the question's name to an appropriate one. Here's what I've been through during installation of cx_Oracle module in Windows 7 - 32 bit version(I think other versions of windows would have similar solutions, but I'm not sure):

  • I have tried to install cx_Oracle using easy_install and I got the error No oracle client installed. I have downloaded oracle basic instant client and oracle sdk instant client for windows from Oracle Official Website and installed it via following steps:

    Unzip oracle basic instant client into directory C:oracleinstant_client_11_1.

    Unzip oracle sdk instant client and copy folder sdk into the directory C:oracleinstant_client_11_1, consequently we have a directory as C:oracleinstant_client_11_1sdk.

    Add C:oracleinstant_client_11_1 to the end of the PATH environment variable.

    Add a new variable named ORACLE_HOME and set C:oracleinstant_client_11_1 for the value.

    Restart computer.

  • I tried to install cx_Oracle using easy_install again and I got error command ‘gcc’ failed: no such file or directory and in some cases unable to find vcvarsall.bat; this was because I didn’t have a C++ compiler, so I followed these steps to solve it:

    Download Microsoft Visual C++ and install it.

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

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

  • I tried to install cx_Oracle using easy_install again and I got error command ‘gcc’ failed with exit status 1; I tried this step to solve it:

    Open file C:Python27Libdistutils cygwincompiler.py and remove all –mno-cygwin occurrences in this file; this is because recent versions of GCC has removed –mno-cygwin option and it shouldn’t be there.

  • I tried to install cx_Oracle using easy_install and it worked.

But during searching in the internet I found a couple of tricks that may be useful:

  • If you got error no module named win32api, it’s because you didn’t install win32 extensions of python on your computer you should download pywin32 module from Source Forge and install it.

  • If you didn’t succeed anyway, you can try an older version of cx_Oracle; but keep in mind all we talked about in the above lines. You can find all versions of cx_Oracle here.

  • If you want to use sqlplus you should do some other steps too. For this purpose search the internet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...