简体   繁体   中英

cx_Oracle 8 Installation (macOS Big Sur)

Issue Statement:

I am currently working on macOS Big Sur and trying to run and install cx_Oracle 8 on macOs Big Sur . After following the steps listed out on the documentation, I am still receiving the following error upon startup.

2022-01-28 10:20:27,085 - root - ERROR - MainThread - 4488076800 - Oracle-Error-Code:0
2022-01-28 10:20:27,086 - root - ERROR - MainThread - 4488076800 - Oracle-Error-Message:DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): no suitable image found.

NOTE: I have of course installed the package pip install cx-Oracle and am importing appropriately import cx_Oracle

What I've tried?

I've tried the following with no luck

Extract the instant client into /opt/oracle/instantclient_19_8

$ ln -s /opt/oracle/instantclient_19_8/libclntsh.dylib /usr/local/lib/

And

mkdir ~/lib
ln -s /opt/oracle/instantclient_19_8/libclntsh.dylib ~/lib/

I do get a promising error, with these, but, I am at a loss, on what to 'try' next

Did find:
    /xxx/xxx/lib/libclntsh.dylib: stat() failed with errno=62". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
enter code here

Work Around

I do have a work around, which involves, adding in a init with a link to my downloaded client, which as you can image is not ideal, as you have to take in and out for each repo, as needed and would never want to commit this to git when the time comes.

import cx_Oracle

cx_Oracle.init_oracle_client(lib_dir=f'/xxx/xxx/xxx/instantclient_19_8')

macOS has clamped down on the use of libraries, which is a pain.

There are two solutions on macOS:

  • Use cx_Oracle.init_oracle_client() as you found. I tend to write it like:
if platform.system() == "Darwin":
 cx_Oracle.init_oracle_client(lib_dir=os.environ.get("HOME")+"/Downloads/instantclient_19_8")
  • Create a sym link like:
cjones@mac:~$ python
Python 3.9.6 (default, Aug 20 2021, 13:36:17) 
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> cx_Oracle
<module 'cx_Oracle' from '/Users/cjones/.pyenv/versions/3.9.6/lib/python3.9/site-packages/cx_Oracle.cpython-39-darwin.so'>
>>> 
cjones@mac:~$ ln -s ~/Downloads/instantclient_19_8/libclntsh.dylib /Users/cjones/.pyenv/versions/3.9.6/lib/python3.9/site-packages/

When Oracle releases a 'thin' Python driver you won't need Instant Client and won't need to do either of these.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM