Ubuntu 16.04下如何便捷安装Python的cx_Oracle模块?
Fixing cx_Oracle Installation in Dockerized Ubuntu 16.04
The error you're hitting happens because cx_Oracle relies on the Oracle Instant Client libraries to talk to remote Oracle databases—libaio is just a basic prerequisite, but you're missing the actual Oracle client binaries. Here's a single command chain that handles all dependencies, sets up the Oracle Instant Client properly, and installs cx_Oracle correctly in your Ubuntu 16.04 Docker environment:
apt-get update && apt-get install -y libaio1 libaio-dev wget unzip && \ wget https://download.oracle.com/otn_software/linux/instantclient/185000/instantclient-basic-linux.x64-18.5.0.0.0dbru.zip && \ unzip instantclient-basic-linux.x64-18.5.0.0.0dbru.zip && \ mv instantclient_18_5 /usr/lib/oracle/18.5/client64/lib && \ mkdir -p /usr/lib/oracle/18.5/client64/include && \ ln -s /usr/lib/oracle/18.5/client64/lib/libclntsh.so.18.1 /usr/lib/oracle/18.5/client64/lib/libclntsh.so && \ echo "/usr/lib/oracle/18.5/client64/lib" > /etc/ld.so.conf.d/oracle-instantclient.conf && \ ldconfig && \ pip install cx_Oracle && \ rm instantclient-basic-linux.x64-18.5.0.0.0dbru.zip
Breakdown of what this does:
- Updates apt and installs
libaio(required for Oracle client I/O operations) pluswget/unzipto fetch and extract the client package - Downloads Oracle Instant Client 18.5 (the latest version fully compatible with Ubuntu 16.04)
- Moves the client files to a standard system path for Oracle libraries
- Creates a symlink for
libclntsh.so(cx_Oracle looks for this unversioned filename, while the package includes a versioned one) - Configures the system's dynamic linker to recognize the Oracle library path
- Refreshes the linker cache so changes take effect immediately
- Installs cx_Oracle via pip
- Cleans up the downloaded zip file to keep your Docker image small
If you're building a Dockerfile, you can add this command directly (or split it into separate RUN commands for better layer caching). Once this completes, you should be able to import cx_Oracle and connect to your remote Oracle database without any issues.
内容的提问来源于stack exchange,提问作者Joe




