windows下安装cx_Oracle的方法

梦想与她 提交于 2019-12-01 15:22:06

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!