pip install mysql-python 失败并出现环境错误:找不到 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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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
我该如何解决此问题?
This is the error I get
(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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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 "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
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
What can I do to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(24)
您的系统上似乎缺少 mysql_config 或者安装程序找不到它。
确保 mysql_config 确实安装。
例如在 Debian/Ubuntu 上你必须安装该软件包:
可能 mysql_config 不在你的路径中,你自己编译时会出现这种情况
mysql 套件。
更新:对于最新版本的 debian/ubuntu(截至 2018 年),它是
It seems mysql_config is missing on your system or the installer could not find it.
Be sure mysql_config is really installed.
For example on Debian/Ubuntu you must install the package:
Maybe the mysql_config is not in your path, it will be the case when you compile by yourself
the mysql suite.
Update: For recent versions of debian/ubuntu (as of 2018) it is
在 Mac OS 中,我只是在终端中运行此命令来修复:
这是我发现的最快修复 - 它将它添加到路径中,但我认为你最好永久添加它(即将其添加到
/etc/ paths
)如果您计划在其他环境中安装 MySQL-python。(在 OSX Mountain Lion 中测试)
In Mac OS, I simply ran this in terminal to fix:
This is the quickest fix I found - it adds it to the path, but I think you're better off adding it permanently (ie add it to
/etc/paths
) if you plan to install MySQL-python in another environment.(tested in OSX Mountain Lion)
对于上述问题可能有多种答案,下面是一个汇总的解决方案。
对于 Ubuntu:
对于 CentOS:
There maybe various answers for the above issue, below is a aggregated solution.
For Ubuntu:
For CentOS:
似乎成功了。
Seemed to do the trick.
如果您使用的是 MAC
全局安装这个
然后像这样导出路径
比全局或在你的venv中无论你喜欢什么
注意:对于python3全局,因为Mac可以同时拥有python2和python2。 3
If you are on MAC
Install this globally
then export path like this
Than globally or in your venv whatever you like
Note: globally for python3 as Mac can have both python2 & 3
您可以使用 MySQL Connector/Python
通过 PyPip 安装
更多信息可以在 MySQL 连接器/Python 1.0.5 beta 公告 博客。
在 Launchpad 上,有 一个很好的示例,说明如何使用库添加、编辑或删除数据。
You can use the MySQL Connector/Python
Installation via PyPip
Further information can be found on the MySQL Connector/Python 1.0.5 beta announcement blog.
On Launchpad there's a good example of how to add-, edit- or remove data with the library.
对于 centos 用户:
yum install -y mysql-devel python-devel python-setuptools
然后
pip install MySQL-python
如果此解决方案不起作用,并打印 gcc 编译错误,例如:
_mysql.c:29:20: error: Python.h: No such file or directory
您需要指定
Python.h
的路径,如下所示:pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python
For centos users:
yum install -y mysql-devel python-devel python-setuptools
then
pip install MySQL-python
If this solution doesn't work, and print gcc compile error like:
_mysql.c:29:20: error: Python.h: No such file or directory
You need to specify the path of
Python.h
, like this:pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python
我试图在 Amazon EC2 Linux 实例上安装 mysql-python ,并且必须安装这些:
但后来我收到此错误:
所以我安装了:
这就成功了。
I was trying to install
mysql-python
on an Amazon EC2 Linux instance and I had to install these :But then I got this error :
So I installed :
And that did the trick.
对于使用 MariaDB 而不是 MySQL 的任何人,解决方案是安装 libmariadbclient-dev 包并使用正确的名称创建指向配置文件的符号链接。
例如这对我有用:
For anyone that is using MariaDB instead of MySQL, the solution is to install the
libmariadbclient-dev
package and create a symbolic link to the config file with the correct name.For example this worked for me:
对于 Linux
这对我有用
For Linux
this works for me
尝试 sudo apt-get build-dep python-mysqldb
Try
sudo apt-get build-dep python-mysqldb
OSX Mavericks
由于 osx Mavericks 和 OSX Mavericks 内部的变化, xcode 开发工具您可能会在安装时遇到错误,
因此使用:
OSX Mavericks
Due to changes within osx mavericks & xcode development tools you may get the error on installation
therefore use :
对于 mariadb,安装 libmariadbclient-dev 而不是 libmysqlclient-dev
for mariadb install libmariadbclient-dev instead of libmysqlclient-dev
我在 Terraform:light 容器中遇到了同样的问题。它基于 Alpine。
在那里你必须安装 mariadb-dev:
但这还不够,因为还缺少所有其他依赖项:
I had the same problem in the Terraform:light container. It is based on Alpine.
There you have to install mariadb-dev with:
But that one is not enough because also all the other dependencies are missed:
您应该先安装
mysql
:然后您可以安装
mysqlclient
:You should install the
mysql
first:Then you can install
mysqlclient
:有时错误取决于实际原因。我们有一个例子,mysql-python 是通过 python-mysqldb debian 包安装的。
一位不知道这一点的开发人员不小心运行了
pip uninstall mysql-python
,然后无法使用pip install mysql-python
恢复,并出现上述错误。pip uninstall mysql-python
已经破坏了 debian 软件包的内容,当然pip install mysql-python
失败了,因为 debian 软件包不需要任何开发文件。在这种情况下,正确的解决方案是 apt-get install --reinstall python-mysqldb ,它将 mysql-python 恢复到原始状态。
sometimes the error depends on the actual cause. we had a case where mysql-python was installed through the python-mysqldb debian package.
a developer who didn't know this, accidentally ran
pip uninstall mysql-python
and then failed to recover withpip install mysql-python
giving the above error.pip uninstall mysql-python
had destroyed the debian package contents, and of coursepip install mysql-python
failed because the debian package didn't need any dev files.the correct solution in that case was
apt-get install --reinstall python-mysqldb
which restored mysql-python to its original state.应遵循的顺序。
然后尝试再次安装MYSQL-python。这对我有用
Sequence to be followed.
Then try to install the MYSQL-python again. That Worked for me
在 Mac 上:
找到 mysql
然后添加到路径
或永久添加
On Mac:
locate mysql
then add to path
or permanently
尝试在 OS X Server 10.6.8 上安装时遇到类似问题。这就是我必须做的。
使用:
MySQL-python 1.2.4b4(源)
MySQL-5.6.19(二进制安装程序)
Python 2.7(二进制安装程序)
注意:在 virtualenv 中安装...
解压缩源代码,打开“distribute_setup.py”并编辑 DEFAULT_VERSION 以使用最新版本的分发工具,如下所示:
保存。打开“site.cfg”文件并取消注释 mysql_config 的路径,使其看起来像这样(引用您自己的 mysql_config 路径):
现在 clean、build 和 make 不会因“mysql_config”未找到错误而失败。
希望这可以帮助其他尝试使用旧 xserve 的人:-)
Had a similar issue trying to install on OS X Server 10.6.8. Here's what I had to do.
Using:
MySQL-python 1.2.4b4 (source)
MySQL-5.6.19 (binary installer)
Python 2.7 (binary installer)
NOTE: Installing in virtualenv...
Unzip source, open 'distribute_setup.py' and edit DEFAULT_VERSION to use the latest version of distribute tools, like so:
Save. Open 'site.cfg' file and uncomment the path to mysql_config so it looks something like (reference your own path to mysql_config):
Now clean, build and make will not fail with the 'mysql_config' not found error.
Hope this helps someone else trying to make use of their old xserves :-)
您的 sudo 路径不知道您的本地路径...进入超级用户模式,添加路径,然后从那里安装它。
您就可以在 OSX 上启动并运行了。现在你有了一个更新的全局 python。
Your sudo path does not know about your local path... go into superuser mode, add the path, and install it from there.
And you're up and running on OSX. Now you have an updated global python.
如果你在虚拟环境中安装了MySQL-python,你应该检查pip版本,如果版本低于9.0.1,请更新它
if you install MySQL-python in your virtual env, you should check the pip version, if the version is older than 9.0.1, please update it
就我而言,我的数据库在容器上运行,而我的 Flask 应用程序在另一个容器上运行,当我尝试更新代码时,应用程序因错误而中断,
堆栈跟踪中的密钥是
因为我的 Flask 应用程序运行的地方没有正确配置 mysql 客户端,所以首先我安装了mysql服务器,然后安装
然后启动MySQL
然后安装flask-mysql包,这次它工作了
这是不同的情况,但在这里发布,因为世界上可能有其他人面临同样的问题
In my case my database is running on container and my flask app is running on another container when i tried updating code app got broke with error
Key in stack trace is
because where my flask app is running doesn't have mysql client properly configured so first i installed mysql server and then install
Then started MySQL
Then install flask-mysql package and this time it worked
This is different case but posting here because may be someone else in the world facing same issue
写于2021年8月27日,
我的macos版本是BigSur(14.4),mysql版本是mysql8。似乎在更高版本的mysql中,他们删除了
my_config.h
文件,但更改为mysql.h
。所以你们应该运行以下 shell:
之后,运行
pip install MySQL-python
一切都会好起来的。write on 27 Aug, 2021
my macos version is BigSur(14.4), and mysql version is mysql8. It seems like in the higher version of mysql, they delete the
my_config.h
files but change to themysql.h
.so your guys should run the following shell:
after that, run
pip install MySQL-python
and everything will be ok.在 MacOS Mojave 上,mysql_config 位于 /usr/local/bin/ 而不是上面指出的 /usr/local/mysql/bin ,因此无需向路径添加任何内容。
on MacOS Mojave, mysql_config is found at /usr/local/bin/ rather than /usr/local/mysql/bin as pointed above, so no need to add anything to path.