问题:pip安装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 "<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?
回答 0
看来您的系统上缺少mysql_config或安装程序找不到它。确保确实安装了mysql_config。
例如,在Debian / Ubuntu上,您必须安装软件包:
sudo apt-get install libmysqlclient-dev
也许mysql_config不在您的路径中,当您自己编译mysql套件时就是这种情况。
更新:对于最新版本的debian / ubuntu(截至2018年),它是
sudo apt install default-libmysqlclient-dev
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:
sudo apt-get install libmysqlclient-dev
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
sudo apt install default-libmysqlclient-dev
回答 1
在Mac OS中,我只是在终端中运行此程序来修复:
export PATH=$PATH:/usr/local/mysql/bin
这是我找到的最快的修复程序-将其添加到路径中,但是/etc/paths
如果您打算在其他环境中安装MySQL-python,最好永久添加(即将其添加到)。
(在OSX Mountain Lion中测试)
In Mac OS, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
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)
回答 2
apt-get install libmysqlclient-dev python-dev
似乎做到了。
apt-get install libmysqlclient-dev python-dev
Seemed to do the trick.
回答 3
上面的问题可能有各种答案,下面是一个汇总的解决方案。
对于Ubuntu:
$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb
对于CentOS:
$ yum install python-devel mysql-devel
There maybe various answers for the above issue, below is a aggregated solution.
For Ubuntu:
$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb
For CentOS:
$ yum install python-devel mysql-devel
回答 4
如果您使用的是MAC,请全局安装
brew install mysql
然后像这样导出路径
export PATH=$PATH:/usr/local/mysql/bin
比全球或您喜欢的任何方式
pip install MySQL-Python
注意:全局适用于python3,因为Mac可以同时拥有python2和3
pip3 install MySQL-Python
If you are on MAC Install this globally
brew install mysql
then export path like this
export PATH=$PATH:/usr/local/mysql/bin
Than globally or in your venv whatever you like
pip install MySQL-Python
Note: globally for python3 as Mac can have both python2 & 3
pip3 install MySQL-Python
回答 5
回答 6
对于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
回答 7
我试图mysql-python
在Amazon EC2 Linux实例上安装,但我必须安装这些:
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
那就成功了。
I was trying to install mysql-python
on an Amazon EC2 Linux instance and I had to install these :
yum install mysql mysql-devel mysql-common mysql-libs gcc
But then I got this error :
_mysql.c:29:20: fatal error: Python.h: No such file or directory
So I installed :
yum install python-devel
And that did the trick.
回答 8
对于任何使用MariaDB而不是MySQL的用户,解决方案是安装libmariadbclient-dev
软件包并创建指向具有正确名称的配置文件的符号链接。
例如,这对我有用:
ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
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:
ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
回答 9
尝试 sudo apt-get build-dep python-mysqldb
Try sudo apt-get build-dep python-mysqldb
回答 10
OSX小牛
由于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
OSX Mavericks
Due to changes within osx mavericks & xcode development tools you may get the error on installation
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
therefore use :
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python
回答 11
对于Linux
这对我有用
yum install python-devel mysql-devel
For Linux
this works for me
yum install python-devel mysql-devel
回答 12
对于mariadb,请安装lib mariadb client-dev而不是libmysqlclient-dev
sudo apt-get install libmariadbclient-dev
for mariadb install libmariadbclient-dev instead of libmysqlclient-dev
sudo apt-get install libmariadbclient-dev
回答 13
您应该安装第mysql
一个:
yum install python-devel mysql-community-devel -y
然后您可以安装mysqlclient
:
pip install mysqlclient
You should install the mysql
first:
yum install python-devel mysql-community-devel -y
Then you can install mysqlclient
:
pip install mysqlclient
回答 14
有时,错误取决于实际原因。我们曾经遇到过通过python-mysqldb debian软件包安装mysql-python的情况。
一个不知道这一点的开发人员,无意中跑了出来,但pip uninstall mysql-python
由于pip install mysql-python
给出上述错误而无法恢复。
pip uninstall mysql-python
已经破坏了debian软件包的内容,当然pip install mysql-python
失败了,因为debian软件包不需要任何dev文件。
在这种情况下,正确的解决方案是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 with pip install mysql-python
giving the above error.
pip uninstall mysql-python
had destroyed the debian package contents, and of course pip 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.
回答 15
我在Terraform:light容器中遇到了同样的问题。它基于高山。
在那里,您必须使用以下命令安装mariadb-dev:
apk add mariadb-dev
但是,这还不够,因为还遗漏了所有其他依赖项:
apk add python2 py2-pip gcc python2-dev musl-dev
I had the same problem in the Terraform:light container. It is based on Alpine.
There you have to install mariadb-dev with:
apk add mariadb-dev
But that one is not enough because also all the other dependencies are missed:
apk add python2 py2-pip gcc python2-dev musl-dev
回答 16
要遵循的顺序。
pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
然后尝试再次安装MYSQL-python。对我有用
Sequence to be followed.
pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
回答 17
尝试在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
现在,清理,构建和制作不会因找不到“ 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:
DEFAULT_VERSION = "0.6.49"
Save. Open ‘site.cfg’ file and uncomment the path to mysql_config so it looks something like (reference your own path to 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
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 :-)
回答 18
您的sudo路径不知道您的本地路径…进入超级用户模式,添加路径,然后从那里安装它。
sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit
您就可以在OSX上运行了。现在,您有了一个更新的全局python。
Your sudo path does not know about your local path… go into superuser mode, add the path, and install it from there.
sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit
And you’re up and running on OSX. Now you have an updated global python.
回答 19
如果在虚拟环境中安装MySQL-python,则应检查pip版本,如果该版本早于9.0.1,请进行更新
pip install --upgrade pip
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
pip install --upgrade pip
回答 20
在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.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。