Try editing the:

    /var/tmp/mod_wsgi-localhost:8080:501/envvars

file and add:

    export DYLD_LIBRARY_PATH=/some/path/to/oracle/lib/directory

Add in there any other Oracle specific environment variable just in case.

Oracle usually puts libraries in strange places and relies on setting 
environment variables to tell applications where they are. On macOS though, the 
DYLD_LIBRARY_PATH environment variable isn't passed through to sub processes in 
certain contexts, so you need to set it in that script file so Apache sees it.

If that works, make a copy of the envvars file to your local area where source 
code is and pass the --envvars option to mod_wsgi-express with name of the file 
to have it use your local copy.

Graham

> On 28 Apr 2020, at 1:48 am, Manasi Gopala <[email protected]> wrote:
> 
> I am trying to setup a rest api to return data from oracle database table.  
> My configuration looks like this:
> OS: macOS Mojave(10.14.6 (18G4032))
> Python:3.8.0 64-bit in virtual env (.venv/bin/python) installed by following 
> instructions here: https://www.python.org/downloads/mac-osx/ 
> <https://www.python.org/downloads/mac-osx/>
> Oracle Instant client installed using instructions here: 
> https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html
>  
> <https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html>
>  (tried with version 19.3 and 18.1)
> installed cx_Oracle using  pip 20.0.2 from 
> /Users/manasi/git/rest-api/.venv/lib/python3.8/site-packages/pip (python 3.8)
> 
> I have a db_test.py file with following code
> import cx_Oracle as orcl
> 
> print("cx_Oracle.version:", orcl.version)
> 
> connection = orcl.connect('user/password@localhost:1521/XEPDB1')
> cursor = orcl.Cursor(connection) 
> 
> print("======")
> sql = "select * from dual"
> res = cursor.execute(sql)
> print(res.fetchall())
> print("======")
> 
> This runs and produces results. I have tested with query for other tables in 
> the schema and got results.
> $ python db_test.py 
> 
> cx_Oracle.version: 7.3.0
> ======
> [('X',)]
> ======
> 
> when I run the same from wsgi.py
> import os
> import sys
> import cx_Oracle as orcl
> 
> def application(environ, start_response):
>     status = '200 OK'
>     output = b'Hello World!'
>     print (dict(os.environ))
>     print(sys.version)
>     print(sys.path)
>     print("cx_Oracle.version:", orcl.version)
> 
>     connection = orcl.connect('user/password@localhost:1521/XEPDB1')
>     cursor = orcl.Cursor(connection) 
> 
>     print("======")
>     sql = "select * from dual"
>     res = cursor.execute(sql)
>     print(res.fetchall())
>     print("======")
> 
>     response_headers = [('Content-type', 'text/plain'),
>                         ('Content-Length', str(len(output)))]
>     start_response(status, response_headers)
> 
>     return [output] 
> $ mod_wsgi-express start-server ./my-app/wsgi.py --port 8080 
> --reload-on-changes --working-directory ./ --mount-point /my-app --log-level 
> info --python-path /Users/manasi/lib
> 
> error_log:
> $ source /Users/manasi/git/rest-api/.venv/bin/activate
> (.venv)$ tail -f /var/tmp/mod_wsgi-localhost:8080:501/error_log [Mon Apr 27 
> 11:35:07.409188 2020] [mpm_prefork:info] [pid 6367] AH00164: Server built: 
> Feb 22 2019 20:20:11
> [Mon Apr 27 11:35:07.409207 2020] [core:notice] [pid 6367] AH00094: Command 
> line: 'httpd (mod_wsgi-express)  -f 
> /var/tmp/mod_wsgi-localhost:8080:501/httpd.conf -D MOD_WSGI_WITH_PYTHON_PATH 
> -D FOREGROUND'
> [Mon Apr 27 11:35:07.409024 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Starting process 'localhost:8080' with threads=5.
> [Mon Apr 27 11:35:07.409773 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Python home /Users/manasi/git/rest-api/.venv.
> [Mon Apr 27 11:35:07.409827 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Initializing Python.
> [Mon Apr 27 11:35:07.421089 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Attach interpreter ''.
> [Mon Apr 27 11:35:07.429142 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Adding '/Users/manasi/lib' to path.
> [Mon Apr 27 11:35:07.433721 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369): 
> Imported 'mod_wsgi'.
> [Mon Apr 27 11:35:07.433813 2020] [wsgi:info] [pid 6369] mod_wsgi (pid=6369, 
> process='localhost:8080', application=''): Loading Python script file 
> '/var/tmp/mod_wsgi-localhost:8080:501/handler.wsgi'.
> [Mon Apr 27 11:35:07.487445 2020] [wsgi:error] [pid 6369] monitor (pid=6369): 
> Starting change monitor.
> [Mon Apr 27 11:35:46.457493 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> {'MOD_WSGI_MODULES_DIRECTORY': '/usr/libexec/apache2', 'TERM_PROGRAM': 
> 'vscode', 'MOD_WSGI_SERVER_ROOT': '/var/tmp/mod_wsgi-localhost:8080:501', 
> 'SHELL': '/bin/bash', 'TERM': 'xterm-256color', 'TMPDIR': 
> '/var/folders/tl/jkkzxl3x2hd5spv5cq02nw6c0000gn/T/', '__PYVENV_LAUNCHER__': 
> '/Users/manasi/git/rest-api/.venv/bin/python3', 'Apple_PubSub_Socket_Render': 
> '/private/tmp/com.apple.launchd.pcoWK8iKv5/Render', 'TERM_PROGRAM_VERSION': 
> '1.44.2', 'LC_ALL': 'en_US.UTF-8', 'USER': 'manasi', 
> 'MOD_WSGI_LISTENER_HOST': 'localhost', 'SSH_AUTH_SOCK': 
> '/private/tmp/com.apple.launchd.HxSkcpD4Q5/Listeners', 
> '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'VIRTUAL_ENV': 
> '/Users/manasi/git/rest-api/.venv', 'PATH': 
> '/Users/manasi/git/rest-api/.venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet',
>  'MOD_WSGI_HTTPS_PORT': 'None', 'PWD': '/Users/manasi/git/rest-api', 'LANG': 
> 'en_US.UTF-8', 'XPC_FLAGS': '0x0', 'MOD_WSGI_HTTP_PORT': '8080', 
> 'XPC_SERVICE_NAME': '0', 'HOME': '/Users/manasi', 'SHLVL': '2', 
> 'MOD_WSGI_GROUP': 'staff', 'MOD_WSGI_USER': 'manasi', 'LOGNAME': 'manasi', 
> 'MOD_WSGI_WORKING_DIRECTORY': '/Users/manasi/git/rest-api', 'COLORTERM': 
> 'truecolor', 'PYTHON_EGG_CACHE': 
> '/var/tmp/mod_wsgi-localhost:8080:501/python-eggs', 'MOD_WSGI_EXPRESS': 
> 'true', 'MOD_WSGI_SERVER_NAME': 'localhost', 'MOD_WSGI_SERVER_ALIASES': '', 
> 'MOD_WSGI_RELOADER_ENABLED': 'true'}
> [Mon Apr 27 11:35:46.457721 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
> [Mon Apr 27 11:35:46.457736 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> [Clang 6.0 (clang-600.0.57)]
> [Mon Apr 27 11:35:46.457748 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> [Mon Apr 27 11:35:46.457769 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> ['/Users/manasi/git/rest-api', '/Users/manasi/lib', 
> '/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip', 
> '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8', 
> '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
>  '/Users/manasi/git/rest-api/.venv/lib/python3.8/site-packages']
> [Mon Apr 27 11:35:46.457790 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> cx_Oracle.version: 7.3.0
> [Mon Apr 27 11:35:46.458170 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> mod_wsgi (pid=6369): Exception occurred processing WSGI script 
> '/var/tmp/mod_wsgi-localhost:8080:501/htdocs/my-app/'.
> [Mon Apr 27 11:35:46.459085 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> Traceback (most recent call last):
> [Mon Apr 27 11:35:46.459128 2020] [wsgi:error] [pid 6369] [remote ::1:53553]  
>  File 
> "/Users/manasi/git/rest-api/.venv/lib/python3.8/site-packages/mod_wsgi/server/__init__.py",
>  line 1514, in handle_request
> [Mon Apr 27 11:35:46.459141 2020] [wsgi:error] [pid 6369] [remote ::1:53553]  
>    return self.application(environ, start_response)
> [Mon Apr 27 11:35:46.459155 2020] [wsgi:error] [pid 6369] [remote ::1:53553]  
>  File "/Users/manasi/git/rest-api/my-app/wsgi.py", line 13, in application
> [Mon Apr 27 11:35:46.459164 2020] [wsgi:error] [pid 6369] [remote ::1:53553]  
>    connection = orcl.connect('user/password@localhost:1521/XEPDB1')
> [Mon Apr 27 11:35:46.459185 2020] [wsgi:error] [pid 6369] [remote ::1:53553] 
> cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client 
> library: "dlopen(libclntsh.dylib, 1): image not found". See 
> https://oracle.github.io/odpi/doc/installation.html#macos for help
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/modwsgi/1b56770b-c269-4204-97f3-d84fa668534a%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/modwsgi/1b56770b-c269-4204-97f3-d84fa668534a%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/modwsgi/2B774F0D-435A-4FF7-9747-2FCF6E61546E%40gmail.com.

Reply via email to