python - ImportError:Apache 中没有名为 cx_Oracle 的模块
问题描述
我在 CentOS7 上用 apache 部署烧瓶
我希望 Oracle 数据库在用户访问时插入或选择。
所以我安装 cx_Oracle
pip install cx_Oracle
并在虚拟环境上运行烧瓶。
flask run
它可以正常工作。
但是我使用 apache 访问 localhost:80,它发生内部服务器错误 500。
在错误日志中
[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
我按照这篇文章使用 apache 部署烧瓶。
https://dev.to/sm0ke/flask-deploy-with-apache-on-centos-minimal-setup-2kb7
并安装 cx_Oracle 并将其复制到我认为需要它的地方。
这里是我的树
/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
但它仍然给出错误。
还有其他方法吗?
解决方案
确保通过下载将所需的 Oracle Instant Client 安装到 Apache 用户
并解压缩到 Apache 用户拥有或可读取和执行的文件夹 - 可以说
/apache/oracle
之后,确保 PATH、ORACLE_HOME 和 LD_LIBRARY_PATH 正确设置为 Apache 用户 - 即
export ORACLE_HOME=/apache/oracle
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
如果您将 Apache 作为服务启动,那么您可能需要将变量设置为 root 或启动 apache 的用户。
推荐阅读
- python - Gmail API ID 不工作,但线程 ID 工作
- ruby-on-rails - config.assets.compile = false - 使 heroku 不在生产中显示我的图像
- c# - 为什么我的身份数据库表没有迁移到 Azure?
- c - 从输入文件中读取字符串/单词和整数
- ruby-on-rails - 将默认日期设置为“所有日期”到 datepicker
- postgresql - 什么 PL/pgSQL 异常与 PostgreSQL 中 Oracle 的 VALUE_ERROR 等效?
- node.js - 通过发送 200 阻止 Express-API 并继续执行?
- maven - 验证代码更改后自述文件中的命令行示例是否正常工作
- spring-security-oauth2 - Spring OAuth2 - 令牌端点的基本身份验证标头中用户名的 URL 编码
- css - 实现删除的css按钮不起作用