mysql_config不存在,pip install mysql-python因EnvironmentError而失败:找不到mysql_config

pip install mysql-python因EnvironmentError而失败:找不到mysql_config

这是我得到的错误

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python

Downloading/unpacking mysql-python

Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded

Running setup.py egg_info for package mysql-python

sh: mysql_config: not found

Traceback (most recent call last):

File "", line 14, in

File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 24, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

Complete output from command python setup.py egg_info:

sh: mysql_config: not found

Traceback (most recent call last):

File "", line 14, in

File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 24, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------

Command python setup.py egg_info failed with error code 1

Storing complete log in /home/zjm1126/.pip/pip.log

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python

Downloading/unpacking mysql-python

Running setup.py egg_info for package mysql-python

sh: mysql_config: not found

Traceback (most recent call last):

File "", line 14, in

File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 24, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

Complete output from command python setup.py egg_info:

sh: mysql_config: not found

Traceback (most recent call last):

File "", line 14, in

File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 24, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------

Command python setup.py egg_info failed with error code 1

Storing complete log in /home/zjm1126/.pip/pip.log

我该怎么做才能解决这个问题?

18个解决方案

1178 votes

系统上似乎缺少mysql_config,或者安装程序找不到它。确保mysql_config确实已安装。

例如,在Debian / Ubuntu上,你必须安装包:

sudo apt-get install libmysqlclient-dev

也许mysql_config不在你的路径中,当你自己编译时就是这种情况mysql套件。

更新:对于最新版本的debian / ubuntu(截至2018年),它是

sudo apt install default-libmysqlclient-dev

Fbo answered 2018-12-19T20:06:13Z

264 votes

运行Mac OSX Mountain Lion,我只是在终端中运行它来修复:

export PATH=$PATH:/usr/local/mysql/bin

这是我发现的最快的修复 - 它将它添加到路径中,但我认为如果您计划在另一个环境中安装MySQL-python,最好永久添加它(即将其添加到/etc/paths)。

Chris Villa answered 2018-12-19T20:06:37Z

93 votes

apt-get install libmysqlclient-dev python-dev

似乎要做的伎俩。

steve-gregory answered 2018-12-19T20:06:57Z

72 votes

对于上述问题可能有各种答案,下面是一个汇总的解决方案。

对于Ubuntu:

$ sudo apt update

$ sudo apt install python-dev

$ sudo apt install python-MySQLdb

对于CentOS:

$ yum install python-devel mysql-devel

user2886440 answered 2018-12-19T20:07:26Z

21 votes

对于centos用户:

Python.h

然后

Python.h

如果此解决方案不起作用,并打印gcc编译错误,如:

Python.h

您需要指定路径Python.h,如下所示:

pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python

lancerex answered 2018-12-19T20:08:16Z

20 votes

您可以使用MySQL Connector / Python

通过PyPi安装

pip install mysql-connector-python

更多信息可以在MySQL Connector / Python 1.0.5 beta公告博客上找到。

在Launchpad上有一个很好的例子,说明如何使用库添加,编辑或删除数据。

Voles answered 2018-12-19T20:08:49Z

20 votes

如果你在MAC上全局安装

brew install mysql

然后像这样导出路径

export PATH=$PATH:/usr/local/mysql/bin

最后全球或在你的venv

pip install MySQL-Python

Zaman Afzal answered 2018-12-19T20:09:18Z

16 votes

我试图在Amazon EC2 Linux实例上安装mysql-python,我必须安装这些:

yum install mysql mysql-devel mysql-common mysql-libs gcc

但后来我收到了这个错误:

_mysql.c:29:20: fatal error: Python.h: No such file or directory

所以我安装了:

yum install python-devel

这就是诀窍。

Emil Davtyan answered 2018-12-19T20:09:50Z

5 votes

OSX Mavericks

由于osx mavericks& xcode开发工具可能会在安装时遇到错误

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

因此使用:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python

Thomas Schwärzl answered 2018-12-19T20:10:19Z

5 votes

对于使用MariaDB而不是MySQL的任何人,解决方案是安装libmariadbclient-dev软件包并使用正确的名称创建指向配置文件的符号链接。

例如,这对我有用:

ln -s /usr/bin/mariadb_config /usr/bin/mysql_config

Alexandru Chirila answered 2018-12-19T20:10:43Z

4 votes

试试sudo apt-get build-dep python-mysqldb

KalamHavij answered 2018-12-19T20:11:03Z

2 votes

对于mariadb安装libmariadbclient-dev而不是libmysqlclient-dev

sudo apt-get install libmariadbclient-dev

Dinesh Sharma answered 2018-12-19T20:11:23Z

1 votes

有时错误取决于实际原因。 我们有一个通过python-mysqldb debian包安装mysql-python的情况。

一个不知道这个的开发人员,意外地运行了apt-get install --reinstall python-mysqldb,然后无法通过pip install mysql-python恢复,给出了上述错误。

apt-get install --reinstall python-mysqldb已经破坏了debian包内容,当然pip install mysql-python失败了,因为debian包不需要任何dev文件。

在这种情况下,正确的解决方案是apt-get install --reinstall python-mysqldb,它将mysql-python恢复到其原始状态。

eMBee answered 2018-12-19T20:11:57Z

1 votes

您应该先安装mysqlclient:

yum install python-devel mysql-community-devel -y

然后你可以安装mysqlclient:

pip install mysqlclient

aircraft answered 2018-12-19T20:12:21Z

0 votes

有一个类似的问题试图在OS X Server 10.6.8上安装。 这是我必须做的。使用:

MySQL-python 1.2.4b4(源码)MySQL-5.6.19(二进制安装程序)Python 2.7(二进制安装程序)注意:在virtualenv中安装...

解压缩源代码,打开'distribute_setup.py'并编辑DEFAULT_VERSION以使用最新版本的分发工具,如下所示:

DEFAULT_VERSION = "0.6.49"

保存。 打开'site.cfg'文件并取消注释mysql_config的路径,使其看起来像(引用自己的mysql_config路径):

# The path to mysql_config.

# Only use this if mysql_config is not on your PATH, or you have some weird

# setup that requires it.

mysql_config = /usr/local/mysql/bin/mysql_config

现在清理,构建和make不会因'mysql_config'找不到错误而失败。希望这有助于其他人试图利用他们的旧xserves :-)

Brad Herdson answered 2018-12-19T20:12:59Z

0 votes

您的sudo路径不知道您的本地路径...进入超级用户模式,添加路径,并从那里安装它。

sudo su

export PATH=$PATH:/usr/local/mysql/bin/

pip install mysql-python

exit

而且你已经在OSX上运行了。 现在你有了一个更新的全局python。

Paul Kenjora answered 2018-12-19T20:13:24Z

0 votes

如果你在你的虚拟环境中安装MySQL-python,你应该检查点数版本,如果版本低于9.0.1,请更新它

pip install --upgrade pip

Albert Chen answered 2018-12-19T20:13:44Z

0 votes

我在Terraform中遇到了同样的问题:轻型容器。 它以Alpine为基础。

在那里你必须安装mariadb-dev:

apk add mariadb-dev

但是那个还不够,因为还错过了所有其他依赖项:

apk add python2 py2-pip gcc python2-dev musl-dev

Alex answered 2018-12-19T20:14:12Z

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值