Python学习:debian下为python2.7安装MySQLdb扩展(mariadb)

本文详细介绍了在Debian系统中,针对默认安装的MariaDB,如何成功安装Python的MySQLdb扩展。由于常规方法无法直接安装,通过搜索apt源并找到libmariadbclient-dev-compat库,成功解决了安装问题,使得Python能够正常引入MySQLdb模块。

一、前言

本来安装MySQLdb的帖子多如过江之鲤鱼,实在是数不胜数,奈何他们服务器上安装的都是mysql,而现在的新服务器,默认下载安装的都是mariadb,所以这篇文章主要记录一下如何安装mariadb对应的MySQLdb扩展。

二、debian下安装

本来以为linux下直接pip install就能下载了,但是实际操作的时候要是要注意的。

Python学习:debian下为python2.7安装MySQLdb扩展(mariadb)
比如网上的方案是:

apt-get install libmysql-dev
apt-get install libmysqlclient-dev
apt-get install python-dev
pip install mysqlclient

这些命令一般情况下是没问题的,但是本机上安装的是maraidb,那就扯淡了

MariaDB [(none)]> select version();
+--------------------------+
| version() |
+--------
Building wheel for mysqlclient (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for mysqlclient (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [81 lines of output] C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:82: SetuptoolsDeprecationWarning: `project.license` as a TOML table is deprecated !! ******************************************************************************** Please use a simple string containing a SPDX expression for `project.license`. You can also use `project.license-files`. (Both options available on setuptools>=77.0.0). By 2026-Feb-18, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! corresp(dist, value, root_dir) C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:61: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! dist._finalize_license_expression() C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\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 :: GNU General Public License v2 or later (GPLv2+) See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() # Options for building extension module: library_dirs: ['C:/mariadb-connector\\lib\\mariadb', 'C:/mariadb-connector\\lib'] libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient'] extra_link_args: ['/MANIFEST'] include_dirs: ['C:/mariadb-connector\\include\\mariadb', 'C:/mariadb-connector\\include\\mysql', 'C:/mariadb-connector\\include'] extra_objects: [] define_macros: [('version_info', (2, 2, 7, 'final', 0)), ('__version__', '2.2.7')] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\connections.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\converters.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\cursors.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\release.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\times.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\_exceptions.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\__init__.py -> build\lib.win-amd64-cpython-314\MySQLdb creating build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\CR.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\ER.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\FLAG.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\__init__.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants running egg_info writing src\mysqlclient.egg-info\PKG-INFO writing dependency_links to src\mysqlclient.egg-info\dependency_links.txt writing top-level names to src\mysqlclient.egg-info\top_level.txt reading manifest file 'src\mysqlclient.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' adding license file 'LICENSE' writing manifest file 'src\mysqlclient.egg-info\SOURCES.txt' copying src\MySQLdb\_mysql.c -> build\lib.win-amd64-cpython-314\MySQLdb running build_ext building 'MySQLdb._mysql' extension creating build\temp.win-amd64-cpython-314\Release\src\MySQLdb D:\VisualStudio\VC\Tools\MSVC\14.44.35207\bin\HostX86\x64\cl.exe /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 7, 'final', 0)" -D__version__=2.2.7 -IC:/mariadb-connector\include\mariadb -IC:/mariadb-connector\include\mysql -IC:/mariadb-connector\include -ID:\python\include -ID:\python\Include -ID:\VisualStudio\VC\Tools\MSVC\14.44.35207\include -ID:\VisualStudio\VC\Tools\MSVC\14.44.35207\ATLMFC\include -ID:\VisualStudio\VC\Auxiliary\VS\include "-ID:\Windows Kits\10\include\10.0.26100.0\ucrt" "-ID:\Windows Kits\10\\include\10.0.26100.0\\um" "-ID:\Windows Kits\10\\include\10.0.26100.0\\shared" "-ID:\Windows Kits\10\\include\10.0.26100.0\\winrt" "-ID:\Windows Kits\10\\include\10.0.26100.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc/MySQLdb/_mysql.c /Fobuild\temp.win-amd64-cpython-314\Release\src\MySQLdb\_mysql.obj _mysql.c src/MySQLdb/_mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory error: command 'D:\\VisualStudio\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mysqlclient Failed to build mysqlclient error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> mysqlclient
最新发布
11-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值