Workaround for "ImportError: DLL load failed while importing mariadb: The specified module could not be found."

Workaround for "ImportError: DLL load failed while importing mariadb: The specified module could not be found."

在 Windows 64 位 Python 3.8.3 上安装 MariaDB Connector/Python 后,我在 import mariadb 中收到以下错误:

ImportError: DLL load failed while importing mariadb: The specified module could not be found.

显然这是 known issue。在问题解决之前,您能否帮我找到解决方法?

列表 venv\app_name\Lib\site-packages\mariadb-0.9.58.dist-info 产生以下结果:

2020-05-25  16:41                 4 INSTALLER
2020-05-25  16:41            27,030 LICENSE
2020-05-25  16:41             2,625 METADATA
2020-05-25  16:41               572 RECORD
2020-05-25  16:41                 8 top_level.txt
2020-05-25  16:41               105 WHEEL
               6 File(s)         30,344 bytes

显然它看起来没有很多有用的东西,因为没有 Python 或 C/C++ 模块。所以也许 pip3 install --pre mariadb 的安装已经无声地失败了(尽管它报告成功)。

我想到了以下候选解决方案:

  1. 使用MySQL Connector/Python连接到MariaDB。这是可行的解决方案吗?
  2. 从源构建 MariaDB Connector/Python 或以其他方式下载预构建的包(如果可用)。但如何做到这一点?

显然,最快和最可靠的解决方案(据我所知)是通过 following the steps from wiki 从源代码构建 MariaDB Connector/Python,具体来说,使用 MSVS 2019 和 MariaDB Connector/C安装后,我在虚拟环境命令行中执行了以下操作:

set MARIADB_CC_INSTALL_DIR="C:\Program Files\MariaDB\MariaDB Connector C 64-bit"
python setup.py build
python setup.py install

这个错误是由一个小错字引起的,MariaDB Connector/C 不是静态链接,而是动态链接,但是 libmariadb.dll 无法加载。

实际上有3个选项:

  1. 自己构建 C/Python,正如 Serge 在他的回答中已经指出的那样。
  2. 安装 MariaDB Connector/C,并将 \lib 和 \lib\plugin 路径中的目录。
  3. 安装 MariaDB Connector/Python 0.9.59-beta,我在几分钟前上传到 pypi.org。