使用新的cx_Oracle模块:python-oracledb
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用新的cx_Oracle模块:python-oracledb相关的知识,希望对你有一定的参考价值。
Oracle的Python模块已由cx_Oracle更名为python-oracledb,本文阐述新的python-oracledb模块安装过程和代码的更改。
先升级pip到最新:
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
$ python3 -m pip install --upgrade pip --user
Collecting pip
Using cached https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-21.3.1
$ pip3 --version
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 21.3.1 from /home/oracle/.local/lib/python3.6/site-packages/pip (python 3.6)
然后安装python-oracledb:
$ python3 -m pip install oracledb --upgrade --user
Collecting oracledb
Downloading oracledb-1.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB)
|████████████████████████████████| 6.1 MB 36.5 MB/s
Requirement already satisfied: cryptography>=3.2.1 in /usr/lib64/python3.6/site-packages (from oracledb) (3.2.1)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python3.6/site-packages (from cryptography>=3.2.1->oracledb) (1.14.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/lib64/python3.6/site-packages (from cryptography>=3.2.1->oracledb) (1.9.1)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=3.2.1->oracledb) (2.14)
Installing collected packages: oracledb
Successfully installed oracledb-1.1.1
然后在代码中:
# 之前
import cx_Oracle
# 现在
import oracledb as cx_Oracle
参考
- The Latest and Greatest Python DB API for Oracle Database by Christopher Jones
- https://stackoverflow.com/questions/72400478/with-python-oracledb-what-does-dpy-4027-no-configuration-directory-to-search-f
- https://github.com/oracle/python-oracledb/issues/47
以上是关于使用新的cx_Oracle模块:python-oracledb的主要内容,如果未能解决你的问题,请参考以下文章
使用新的cx_Oracle模块:python-oracledb