如何在python中安装mysqlclient?
Posted
技术标签:
【中文标题】如何在python中安装mysqlclient?【英文标题】:How to install mysqlclient in python? 【发布时间】:2019-12-29 19:11:01 【问题描述】:我是 Python 新手,来自 Java 和 JS 背景,
我已经在本地机器上安装了 Python 和 Pip,
我正在尝试使用 mysql 学习 Django,
但是我无法使用 pip 安装 mysqlclient
,我使用以下命令来安装 -
pip install mysqlclient
出现以下错误 -
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/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 pip-egg-info
cwd: /private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/
Complete output (12 lines):
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
截图 -
【问题讨论】:
试试,pip install pymysql
。 pypi.org/project/PyMySQL
嗨,它似乎已经安装了,但是mysqlclient
和pymysql
之间有什么区别?以后会不会导致配置问题?
pymysql
是一个纯 Python MySQL 客户端,而 mysqlclient
需要 mysql-connector-c
。如果您想阅读我的内容,请查看answer。
所以没有代码更改对吗?我可以像往常一样使用 MySql 吗?这里唯一的区别是,我们使用不同的客户端是吗?
没什么区别,照常使用即可。
【参考方案1】:
mysqlclient
需要额外的 c
库。
对于 linux (Debian):$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
对于 Mac:$ brew install mysql
进一步阅读home page
【讨论】:
【参考方案2】:我正在解决以下过程中的错误
Python 3.8.0
首先在 Homebraw 中安装,输入以下命令。在终端输入此命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install mariadb-connector-c
pip install mysqlclient
更多问题遵循本教程 https://medium.com/@MrWeeble/homebrew-on-mac-and-pythons-mysqlclient-ea44fa300e70
【讨论】:
工作于Python 3.8.2
和macOS Big Sur (M1)
以上是关于如何在python中安装mysqlclient?的主要内容,如果未能解决你的问题,请参考以下文章
在 cPanel 上的 django 项目中安装 mysqlclient 时出错