You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.8安装mariadb 1.1.3后导入报错ModuleNotFoundError求助

解决Python 3.8环境下mariadb模块导入失败问题

问题描述

在Python 3.8虚拟环境中通过pip3安装mariadb包后,执行导入操作时报错:

(scrap_venv) apnow@web:/var/sas/scrap$ python
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mariadb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/sas/scrap_venv/lib/python3.8/site-packages/mariadb/__init__.py", line 6, in <module>
    from ._mariadb import (
ModuleNotFoundError: No module named 'mariadb._mariadb'
>>>

执行pip3 show mariadb确认包已安装:

Name: mariadb
Version: 1.1.3
Summary: Python MariaDB extension
Home-page: https://www.github.com/mariadb-corporation/mariadb-connector-python
Author: Georg Richter
Author-email:
License: LGPL 2.1
Location: /var/sas/scrap_venv/lib/python3.8/site-packages
Requires:
Required-by:

解决思路

  • 安装系统级MariaDB开发依赖:mariadb Python包依赖系统的MariaDB客户端库,Debian/Ubuntu系执行sudo apt-get install libmariadb-dev,RHEL/CentOS系执行sudo yum install mariadb-devel。完成后卸载并重新安装mariadb包:pip uninstall mariadb && pip install mariadb
  • 确认虚拟环境激活状态:确保终端提示符显示(scrap_venv),或直接使用虚拟环境内的pip路径安装:/var/sas/scrap_venv/bin/pip install mariadb
  • 更换兼容版本安装:尝试安装与Python 3.8兼容性更好的版本,比如pip install mariadb==1.0.11或pip install mariadb==1.2.0
  • 补全编译环境:安装mariadb包需要编译工具,Debian/Ubuntu系执行sudo apt-get install build-essential,RHEL/CentOS系执行sudo yum install gcc-c++,之后重新安装mariadb包

内容的提问来源于stack exchange,提问作者apnow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:06:19