【问题标题】:Python MariaDB pip install failed, missing mariadb_configPython MariaDB pip 安装失败,缺少 mariadb_config
【发布时间】:2020-06-25 21:58:30
【问题描述】:

我正在使用 Linux Ubuntu 18.04 和 python 3。我正在尝试在 maria-db 和我的 python 脚本之间建立连接。因此我必须安装 mariadb 包。
我已经安装了:

sudo apt install mariadb-server

但是当我尝试时:

pip install mariadb

我收到以下错误:

Collecting mariadb
  Using cached mariadb-1.0.0.tar.gz (78 kB)

    ERROR: Command errored out with exit status 1:
     command: /home/niklas/Desktop/Stuff/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pycharm-packaging/mariadb/setup.py'"'"'; __file__='"'"'/tmp/pycharm-packaging/mariadb/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-wfnscxnz
         cwd: /tmp/pycharm-packaging/mariadb/
    Complete output (12 lines):
    /bin/sh: 1: mariadb_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pycharm-packaging/mariadb/setup.py", line 26, in <module>
        cfg = get_config(options)
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 49, in get_config
        cc_version = mariadb_config(config_prg, "cc_version")
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 27, in mariadb_config
        "mariadb_config not found.\nPlease make sure, that MariaDB Connector/C is installed on your system, edit the configuration file 'site.cfg' and set the 'mariadb_config'\noption, which should point to the mariadb_config utility.")
    OSError: mariadb_config not found.
    Please make sure, that MariaDB Connector/C is installed on your system, edit the configuration file 'site.cfg' and set the 'mariadb_config'
    option, which should point to the mariadb_config utility.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

谁能帮帮我?

编辑:

我现在已经能够连接到服务器,但不能使用 mariadb 包。 (https://linuxhint.com/connect_mariadb_pymysql/)

【问题讨论】:

  • 我都检查过了,但都没有帮助
  • 您是否尝试为您的 python 版本使用非默认 pip 进行安装?

标签: python sql python-3.x pip mariadb


【解决方案1】:

安装 MariaDB Connector/C,这是一个依赖项。

sudo apt-get install libmariadb3 libmariadb-dev

使用 PIP 安装 MariaDB Connector/Python。

pip3 install mariadb

【讨论】:

    【解决方案2】:

    要安装 mariadb python 模块,您必须安装最新版本的 MariaDB Connector/C,最低要求版本为 3.1.5,afaik Ubuntu 18.04 有 3.0.3。

    MariaDB Connector/C Download Page 上提供了用于仿生的 Connector/C 的实际版本。

    如果要将其安装在特殊目录中,请确保 PATH 和 LD_LIBRARY_PATH 指向 bin 和 lib 目录。

    我还建议使用最新版本的 MariaDB Server,尤其是非常快的 executemany() 方法在 MariaDB Server

    【讨论】:

    • 假设您将连接器/C 提取到:/usr/local/src/mariadb-connector/mariadb-connector-c-3.1.12-debian-buster-amd64,那么您可以运行此命令:PATH=/usr/local/src/mariadb-connector-c-3.1.12-debian-buster-amd64/bin:$PATH LD_LIBRARY_PATH=/usr/local/src/mariadb-connector-c-3.1.12-debian-buster-amd64/lib:$LD_LIBRARY_PATH pip3 install mariadb
    【解决方案3】:

    看来您需要先在您的操作系统上安装它。 你可以按照这个guide来正确安装。

    【讨论】:

    • 我已按照该指南进行操作,但仍然遇到同样的问题
    • 你不需要安装整个 MariaDB 服务器来让 Python 连接到它。 Q 要求用户只安装 mariadb 连接器。数据库可能与 Python 程序不在同一台服务器上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多