windows下安装cx_Oracle的方法

Install cx_Oracle

Use Python’s Pip package to install cx_Oracle from PyPI:

python -m pip install cx_Oracle --upgrade

This will download and install a pre-compiled binary if one is available for your architecture. If a pre-compiled binary is not available, the source will be downloaded, compiled, and the resulting binary installed.

Install Oracle Client

Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance. Oracle Client versions 12.2, 12.1 and 11.2 are supported.

  • If your database is remote, then download the free Oracle Instant Client “Basic” or “Basic Light” package for your operating system architecture.
  • Alternatively use the client libraries already available in a locally installed database such as the free Oracle XE release.
Oracle Instant Client Zip Files

To use cx_Oracle with Oracle Instant Client zip files:

  1. Download an Oracle 11.2, 12.1 or 12.2 “Basic” or “Basic Light” zip file: 64-bit or 32-bit, matching your Python architecture.

  2. Unzip the package into a single directory that is accessible to your application, for example C:\oracle\instantclient_12_2.

  3. Set the environment variable PATH to include the path that you created in step 2. For example, on Windows 7, update PATH in Control Panel -> System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> PATH. Alternatively use SET to change your PATH in each command prompt window before you run python.

    If you have other Oracle software installed, then when you use Python you will need to make sure that the Instant Client directory, e.g. C:\oracle\instantclient_12_2, occurs in PATH before any other Oracle directories.

    Restart any open command prompt windows.

  4. Oracle Instant Client libraries require a Visual Studio redistributable with a 64-bit or 32-bit architecture to match Instant Client’s architecture. Each Instant Client version requires a different redistributable version:

  5. If you intend to co-locate optional Oracle configuration files such as tnsnames.orasqlnet.oraor oraaccess.xml with Instant Client, then create a network\admin subdirectory, for exampleC:\oracle\instantclient_12_2\network\admin.

    This is the default Oracle configuration directory for executables linked with this Instant Client.

    Alternatively, Oracle configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.

测试:

import

os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' 

os.environ['path'] = 'D:/instantclient_12_2/' 

import cx_Oracle

如果不设置path,可以在py中设置path

转载于:https://my.oschina.net/leboo/blog/1842462

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值