Summary of pydev's access to the oracle database

Source: Internet
Author: User
Tags dsn

Environment: xp sp3 + eclipse + pydev 2.2 + Python 3.2 + Oracle 10g client + cx_Oracle-5.1.1-10g

Assume that your pydev environment has been configured, if not, the online Plugin: first install python, then install JDK-SE, eclipse decompression can be used, decompress pydev and copy it to the eclipse \ dropins directory to use it .... I won't talk about how to build a project.

Now we start to install cx_oracle. It is an installation package in windows and runs it directly. By default, it will find out where your python is installed, and cx_oracle should also be installed in that directory, you don't need to make any changes. Just click Next. If an error occurs, your cx_oracle version may have a problem and the version must be matched.

Then install the Oracle client. Here you only need to install instantclient,

After the installation is complete, find the OCI in it. DLL and oraociei10.dll files, copy them to the C: \ python32 \ Lib \ Site-packages directory. If they are not installed in this directory, modify them accordingly. DLL cannot be found when this file is not run.

Next, configure the environment variables, mainly system variables:

Add the variable name ORACLE_HOME = F: \ oracle \ ora92; // change it to your corresponding directory.

Add F: \ oracle \ ora92 \ bin at the beginning of path; // change it to your corresponding directory,

I originally installed 9i, but cx_oracle does not support 9i modules, So I installed 10 Gb cx_oracle. In this way, a 10 Gb client must be installed, fortunately, you only need to install instantclient. After you have installed this instantclient, you find that there is no bin directory in the installation directory. You only have installed the complete client. Don't worry, you can use 9i.

When you enter

Import cx_oracle

Db = cx_Oracle.connect (user = 'rses ', password = 'rses', dsn = '192. 0.0.1: 127/RSES ')
Print (db. version)
Db. close

It should be successful, but not in pydev. Hey hey, you need to do something like this:

Import OS
Import cx_Oracle
OS. environ ['oracle _ home'] = 'C:/ORACLE/product/10.2.0/client_1 '// change it to your directory.
OS. environ ['LD _ LIBRARY_PATH '] = 'C:/oracle/product/10.2.0/client_1/lib' // change it to your directory.

Db = cx_Oracle.connect (user = 'rses ', password = 'rses', dsn = '2017. 0.0.1: 1521/RSES ') // your username, password, and service name are both RSES. Please modify the password accordingly.
Print (db. version)
Db. close

The ORA-12705: Cannot access NLS data files or invalid environment specified error occurs. Modify as follows:

For Windows, \ HKEY_LOCAL_MACHINE \ SOFTWARE \ ORACLE search key NLS_LANG in the registry. This key is created by the Oracle standard client and the value is NA. This caused a ORA-12705 error. The solution is to change NA to SIMPLIFIED CHINESE_CHINA.ZHS16GBK.

It is said that pydev cannot reference system variables, that is, the system variables you set above do not exist for pydev, so you must set the environment variables in the code. This is not what I invented. I read it on the foreigners forum. Foreigners are foreigners and cows.

After a day, I finally got it. Haha ....

Note: The settings in OS. environ are not mandatory today. The last time may be because the system environment variables are not properly configured, it seems that the first success may be an accident and the key must be found.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.