安装mysqlclient报错:OSError: mysql_config not found

在Ubuntu系统中,安装mysqlclient时可能会遇到包缺失的问题。需要先安装default-mysql-server和default-mysql-client,然后替换安装libmysqlclient-dev为default-libmysqlclient-dev,最后通过pip成功安装mysqlclient。建议使用虚拟环境来避免权限和系统包冲突。
摘要由CSDN通过智能技术生成

mysqlclient 是一个 Python 程序包,它提供了一个 Python 的 MySQL 客户端库,用于连接和操作 MySQL 数据库。在安装 mysqlclient 之前,需要确保系统已经安装了 MySQL 的 C 客户端库,否则安装过程会失败。

环境安装:

如果使用传统的
apt-get install mysql-server
会报错:

# apt-get install mysql-server mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package mysql-client is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'mysql-server' has no installation candidate
E: Package 'mysql-client' has no installation candidate

换成一下命令即可:

apt-get install default-mysql-server
apt-get install default-mysql-client

安装好mysql环境后还需安装libmysqlclient-dev和python3-dev
同样命令还是需要修改:

root@e262e2b27b67:/home/together_album# apt-get install libmysqlclient-dev python3-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package libmysqlclient-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libmariadb-dev-compat libmariadb-dev

E: Package 'libmysqlclient-dev' has no installation candidate

换成一下命令,即可

apt-get install default-libmysqlclient-dev python3-dev

安装好环境后就可以下载mysqlclient了
如下:

root@e262e2b27b67:/home/together_album# pip install mysqlclient
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting mysqlclient
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.1.1-cp37-cp37m-linux_x86_64.whl size=114715 sha256=77f8bf6d5e3e8c4311b0132d1b9e3e93c8b468990804aeb09b3568b92688a5c6
  Stored in directory: /root/.cache/pip/wheels/3c/5c/f8/669aadcd2c552c9baaf835b360d375adc2cd97b99c5b3de312
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.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

[notice] A new release of pip is available: 23.0.1 -> 23.2
[notice] To update, run: pip install --upgrade pip
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值