简体   繁体   中英

ImportError: No module named cx_Oracle in apache

I deploy flask with apache on CentOS7

And I want Oracle database to insert or select when user access.

So I install cx_Oracle

pip install cx_Oracle

And run flask on virtual env.

flask run

It work with no error.

But I access to localhost:80 using apache, It occur Internal Server Error 500.

In error_log

[Fri Oct 23 09:12:34.623473 2020] [mpm_prefork:notice] [pid 475] AH00170: caught SIGWINCH, shutting down gracefully
[Fri Oct 23 09:12:35.678302 2020] [lbmethod_heartbeat:notice] [pid 510] AH02282: No slotmem from mod_heartmonitor
[Fri Oct 23 09:12:35.681622 2020] [mpm_prefork:notice] [pid 510] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Fri Oct 23 09:12:35.681665 2020] [core:notice] [pid 510] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Fri Oct 23 09:12:38.074902 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Target WSGI script '/var/www/hitme/wsgi.py' cannot be loaded as Python module.
[Fri Oct 23 09:12:38.074946 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Exception occurred processing WSGI script '/var/www/hitme/wsgi.py'.
[Fri Oct 23 09:12:38.074973 2020] [:error] [pid 513] [client 172.17.0.1:33640] Traceback (most recent call last):
[Fri Oct 23 09:12:38.074994 2020] [:error] [pid 513] [client 172.17.0.1:33640]   File "/var/www/hitme/wsgi.py", line 10, in <module>
[Fri Oct 23 09:12:38.075058 2020] [:error] [pid 513] [client 172.17.0.1:33640]     from app import app as application
[Fri Oct 23 09:12:38.075070 2020] [:error] [pid 513] [client 172.17.0.1:33640]   File "/var/www/hitme/app/__init__.py", line 4, in <module>
[Fri Oct 23 09:12:38.075138 2020] [:error] [pid 513] [client 172.17.0.1:33640]     import cx_Oracle
[Fri Oct 23 09:12:38.075162 2020] [:error] [pid 513] [client 172.17.0.1:33640] ImportError: No module named cx_Oracle

I followed this article for deploy flask with apache.

https://dev.to/sm0ke/flask-deploy-with-apache-on-centos-minimal-setup-2kb7

and install cx_Oracle and I copied it where I thought I needed it.

Here my tree

 /etc/httpd/modules/
              |-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
              |-cx_Oracle-8.0.1.dist-info

/var/www/hitme/lib/python3.6/site-packages
                                |-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
                                |-cx_Oracle-8.0.1.dist-info

/usr/local/lib/python3.6/site-packages
                                |-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
                                |-cx_Oracle-8.0.1.dist-info

But it still gives the error.

Is there any other way?

Ensure that the required Oracle Instant Client is installed to the Apache user by downloading

https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip

and unzip ut to a folder Apache user owns or is accessible for read and execute - lets say

/apache/oracle

After that, ensure PATH, ORACLE_HOME and LD_LIBRARY_PATH ist set properly as Apache User - ie

export ORACLE_HOME=/apache/oracle
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

If you start Apache as service then you may need to set the variables to root or user who starts apache.

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