Use Python’s Pip package to install cx_Oracle from PyPI:html
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.python
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.redis
- 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.
To use cx_Oracle with Oracle Instant Client zip files:sql
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.express
Unzip the package into a single directory that is accessible to your application, for example C:\oracle\instantclient_12_2
.windows
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.oracle
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.app
Restart any open command prompt windows.ide
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:測試
- For Instant Client 11.2 install VS 2005 64-bit or VS 2005 32-bit
- For Instant Client 12.1 install VS 2010
- For Instant Client 12.2 install VS 2013
If you intend to co-locate optional Oracle configuration files such as tnsnames.ora
, sqlnet.ora
or 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