当前位置: 首页 > news >正文

部署Superset BI(五)连接oracle数据库失败

折腾完了hana和sqlserver数据库的连接,开始折腾oracle数据库连接
1.requirements-local.txt配置
尝试在requirements-local.txt中设置,结果容器弄瘫痪了,拉不起来了,只要又去掉修改
root@Nocobase:/usr/superset/superset/docker# echo "cx_Oracle">> requirements-local.txt

前面配置sql server只是不能连接,现在连驱动安装都不给脸了。只能手动了。
2.进入到容器中,安装cx_Oracle
root@Nocoly:/superset_data/superset/docker# docker exec -it superset_app bash
root@3da2ba740404:/app# pip install cx_Oracle
Collecting cx_Oracle
  Downloading cx_Oracle-8.3.0.tar.gz (363 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 363.9/363.9 kB 1.7 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: cx_Oracle
  Building wheel for cx_Oracle (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for cx_Oracle (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [24 lines of output]
      <string>:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
      /tmp/pip-build-env-jkj_873l/overlay/lib/python3.11/site-packages/setuptools/config/expand.py:126: SetuptoolsWarning: File '/tmp/pip-install-0tywwoqt/cx-oracle_1429cd634a274461b4a2f485e86fc032/README.md' cannot be found
        return '\n'.join(
      /tmp/pip-build-env-jkj_873l/overlay/lib/python3.11/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated.      !!

              ********************************************************************************
              Please consider removing the following classifiers in favor of a SPDX license expression:

              License :: OSI Approved :: BSD License

              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
              ********************************************************************************      !!
        self._finalize_license_expression()
      running bdist_wheel
      running build
      running build_ext
      building 'cx_Oracle' extension
      creating build/temp.linux-x86_64-cpython-311/odpi/src
      creating build/temp.linux-x86_64-cpython-311/src
      gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DCXO_BUILD_VERSION=8.3.0 -Iodpi/include -Iodpi/src -I/usr/local/include/python3.11 -c odpi/src/dpiConn.c -o build/temp.linux-x86_64-cpython-311/odpi/src/dpiConn.o
      error: command 'gcc' failed: No such file or directory
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cx_Oracle
Failed to build cx_Oracle
ERROR: Could not build wheels for cx_Oracle, which is required to install pyproject.toml-based projects
3.安装pyproject

既然需要pyproject,我们就安装pyproject
root@3da2ba740404:/app# pip install pyproject
Collecting pyproject
  Downloading pyproject-1.3.1.tar.gz (7.9 kB)
  Preparing metadata (setup.py) ... done
Collecting Jinja2 (from pyproject)
  Using cached jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB)
Collecting MarkupSafe>=2.0 (from Jinja2->pyproject)
  Using cached MarkupSafe-3.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.0 kB)
Using cached jinja2-3.1.6-py3-none-any.whl (134 kB)
Using cached MarkupSafe-3.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23 kB)
Building wheels for collected packages: pyproject
  Building wheel for pyproject (setup.py) ... done
  Created wheel for pyproject: filename=pyproject-1.3.1-py3-none-any.whl size=10995 sha256=b10093ffdb373bfb9c443970151ca6a9331234ee95133f5a406684c037d5b61a
  Stored in directory: /app/superset_home/.cache/pip/wheels/49/aa/0a/7d523f715bad8c2fa31a4418828706fa516810791845f287c4
Successfully built pyproject
Installing collected packages: MarkupSafe, Jinja2, pyproject
Successfully installed Jinja2-3.1.6 MarkupSafe-3.0.2 pyproject-1.3.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
4.再次安装cx_Oracle

pyproject安装成功再安装cx_Oracle,但是还是一样的错误
root@3da2ba740404:/app# pip install cx_Oracle

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cx_Oracle
Failed to build cx_Oracle
ERROR: Could not build wheels for cx_Oracle, which is required to install pyproject.toml-based projects

查看pip,pyproject是安装成功的。
root@3da2ba740404:/app# pip freeze
Jinja2==3.1.6
MarkupSafe==3.0.2
pymssql==2.3.2
pyproject==1.3.1
uv==0.6.9
root@3da2ba740404:/app#


5.解决gcc

错误提示中还和gcc有关系。
root@Nocoly:/superset_data/superset/docker# docker exec -it superset_app bash
root@9388cd50484a:/app# apt-get update
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8792 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [250 kB]
Fetched 9310 kB in 3s (3003 kB/s)
Reading package lists... Done
root@9388cd50484a:/app# apt-get install -y build-essential
etting up gpg-wks-server (2.2.40-1.1) ...
Setting up cpp (4:12.2.0-3) ...
Setting up binutils-x86-64-linux-gnu (2.40-2) ...
Setting up gpg-wks-client (2.2.40-1.1) ...
Setting up libstdc++-12-dev:amd64 (12.2.0-14) ...
Setting up binutils (2.40-2) ...
Setting up dpkg-dev (1.21.22) ...
Setting up gcc-12 (12.2.0-14) ...
Setting up gnupg (2.2.40-1.1) ...
Setting up g++-12 (12.2.0-14) ...
Setting up gcc (4:12.2.0-3) ...
Setting up g++ (4:12.2.0-3) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (12.9) ...
Processing triggers for libc-bin (2.36-9+deb12u10) ...

root@9388cd50484a:/app# apt-get install gcc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gcc is already the newest version (4:12.2.0-3).
gcc set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
6.再次安装cx_Oracle
root@9388cd50484a:/app# pip3 install cx_Oracle
Collecting cx_Oracle
  Using cached cx_Oracle-8.3.0.tar.gz (363 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: cx_Oracle
  Building wheel for cx_Oracle (pyproject.toml) ... done
  Created wheel for cx_Oracle: filename=cx_oracle-8.3.0-cp311-cp311-linux_x86_64.whl size=873373 sha256=bee4e3e3421b69410369c2a7fca95b9c8f6fd08bb47713251093437573bf0613
  Stored in directory: /app/superset_home/.cache/pip/wheels/e0/41/f9/63e9c4d1ec7b2e8faffc1d6f3219c2e168c306b042d77e2b6f
Successfully built cx_Oracle
Installing collected packages: cx_Oracle
Successfully installed cx_Oracle-8.3.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
安装成功。
7.配置连接,测试失败
使用连接串oracle://system:CNpass2019@172.168.0.16:1521/?service_name=orcl
配置测试时提示错误:
ERROR: Could not load database driver: OracleEngineSpec看起来还是无法连接oracle
superset_app          |   File "/app/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/oracle/cx_oracle.py", line 1068, in dbapi
superset_app          |     import cx_Oracle
superset_app          | ModuleNotFoundError: No module named 'cx_Oracle'

再次修改requirements-local.txt ,启动的时候一直报错,还是提示gcc相关的错误。见鬼。

8.安装oracle client
--下载

找到cx_oracle的网站,https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#install-cx-oracle,这个里面有一大段话:
Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance.
于是转头开始安装oracle client.
在Oracle网站上找到client下载地址,wget下载:
root@4e7cbd9d89c1:/app# mkdir /opt/oracle
root@4e7cbd9d89c1:/app# cd /opt/oracle
root@4e7cbd9d89c1:/opt/oracle# wget https://download.oracle.com/otn/linux/instantclient/122010/instantclient-basic-linux.x64-12.2.0.1.0.zip
root@4e7cbd9d89c1:/opt/oracle# ls
instantclient-basic-linux.x64-12.2.0.1.0.zip
root@4e7cbd9d89c1:/opt/oracle# unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
bash: unzip: command not found
root@4e7cbd9d89c1:/opt/oracle# pip install unzip
Collecting unzip
  Downloading unzip-1.0.0.tar.gz (704 bytes)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: unzip
  Building wheel for unzip (setup.py) ... done
  Created wheel for unzip: filename=unzip-1.0.0-py3-none-any.whl size=1282 sha256=d6297bd5a18634f65be9ec88800f630352a6ba97c6db780ceb42ef274358d82b
  Stored in directory: /app/superset_home/.cache/pip/wheels/3c/4d/b3/ddd83a91322fba02a91898d3b006090d1df1d3b0ad61bd8b36
Successfully built unzip
Installing collected packages: unzip
Successfully installed unzip-1.0.0

root@4e7cbd9d89c1:/opt/oracle# unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-basic-linux.x64-12.2.0.1.0.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of oracle.zip or
        oracle.zip.zip, and cannot find oracle.zip.ZIP, period.
root@4e7cbd9d89c1:/opt/oracle# ls
instantclient-basic-linux.x64-12.2.0.1.0.zip
文件明明存在,但是解压不了,原因是因为oracle下载需要登录。在宿主机上登录oracle下载后,拷贝到docker中。
--拷贝docker cp
root@Nocoly:~$ docker cp /home/admin/instantclient-basic-linux.x64-12.2.0.1.0.zip superset_app:/opt/oracle/
Successfully copied 69MB to superset_app:/opt/oracle/
root@Nocoly:~$ docker exec -it 4e7cbd9d89c1 bash
root@4e7cbd9d89c1:/app# cd /opt/oracle
root@4e7cbd9d89c1:/opt/oracle# ls
instantclient-basic-linux.x64-12.2.0.1.0.zip
root@4e7cbd9d89c1:/opt/oracle#  unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-basic-linux.x64-12.2.0.1.0.zip
  inflating: instantclient_12_2/adrci
  inflating: instantclient_12_2/BASIC_README
  inflating: instantclient_12_2/genezi
  inflating: instantclient_12_2/libclntshcore.so.12.1
  inflating: instantclient_12_2/libclntsh.so.12.1
  inflating: instantclient_12_2/libipc1.so
  inflating: instantclient_12_2/libmql1.so
  inflating: instantclient_12_2/libnnz12.so
  inflating: instantclient_12_2/libocci.so.12.1
  inflating: instantclient_12_2/libociei.so
  inflating: instantclient_12_2/libocijdbc12.so
  inflating: instantclient_12_2/libons.so
  inflating: instantclient_12_2/liboramysql12.so
  inflating: instantclient_12_2/ojdbc8.jar
  inflating: instantclient_12_2/uidrvci
  inflating: instantclient_12_2/xstreams.jar
--安装libaio1

root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# apt install libaio
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libaio
root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# apt install libaio1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
--设置环境变量
root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# ldconfig

root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH

root@4e7cbd9d89c1:/opt/oracle/instantclient_12_2# exit
exit
--重启容器
root@Nocoly::~$ docker restart superset_app
superset_app
root@Nocoly::~$ docker exec -it 4e7cbd9d89c1 bash

9.配置连接,失败
还是同样的错误:ModuleNotFoundError: No module named 'cx_oracle'
root@4e7cbd9d89c1:/app# python3
Python 3.11.11 (main, Apr  8 2025, 01:39:46) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cx_oracle'

oracle client已经安装了,cx_oracle已经安装了,为什么还是提示“No module named 'cx_oracle”?环境变量问题?
 

root@4e7cbd9d89c1:/app# python -m site
sys.path = [
    '/app',
    '/app/pythonpath',
    '/app/docker/pythonpath_dev',
    '/usr/local/lib/python311.zip',
    '/usr/local/lib/python3.11',
    '/usr/local/lib/python3.11/lib-dynload',
    '/app/.venv/lib/python3.11/site-packages',
]
USER_BASE: '/app/superset_home/.local' (doesn't exist)
USER_SITE: '/app/superset_home/.local/lib/python3.11/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
root@4e7cbd9d89c1:/app# cd /app/.venv/lib/python3.11/site-packages
这个目录下真的找不到cx_oracle,再安装一次看看
root@4e7cbd9d89c1:/app#  pip3 install cx_oracle
Requirement already satisfied: cx_oracle in /usr/local/lib/python3.11/site-packages (8.3.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
安装路径在/usr/local/lib/python3.11/site-packages (8.3.0),而sys.path 中并没有此路径,那我添加路径再测试。

>>> sys.path.append('/usr/local/lib/python3.11/site-packages')
>>> import cx_oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

结果还是同样的错误,python里面测试如此,superset里面肯定没戏,彻底卡住了,失败!我想换条路走走了。

相关文章:

  • LlamaIndex 第七篇 结构化数据提取
  • 进程(沉淀中)
  • ElasticSearch进阶
  • 大数据模型的构建与优化
  • 找银子 题解(c++)
  • C++ 核心基础:数字、数组、字符串、指针与引用详解
  • springboot3+vue3融合项目实战-大事件文章管理系统-更新用户密码
  • TypeScript 装饰器详解
  • Kotlin Multiplatform--03:项目实战
  • 六大设计原则
  • 2025低空经济发展趋势
  • css背景相关
  • PyGame游戏开发(含源码+演示视频+开结题报告+设计文档)
  • spark算子介绍
  • 单片机-STM32部分:12、I2C
  • Redis设计与实现——数据结构与对象
  • python实战项目69:基于Python爬虫的链家二手房数据采集方法研究
  • 宝塔centos7.6安装redis失败
  • DeepSeek:开启能源领域智能化变革新时代
  • Linux `uname` 指令终极指南
  • 首个偏头痛急性治疗药物可缓解前期症状
  • 国务院关税税则委员会关于调整对原产于美国的进口商品加征关税措施的公告
  • 迪奥部分客户数据遭泄露,公司称正持续展开调查
  • 美股全线收涨:道指涨逾千点,纳斯达克中国金龙指数涨5.4%
  • 铁路部门:确保沿线群众安全,焦柳铁路6个区段将陆续安装防护栅栏
  • 上海现有超12.3万名注册护士,本科及以上学历占一半