pip install mysql-python 失败并出现环境错误:找不到 mysql_config

发布于 2024-10-20 02:36:40 字数 2941 浏览 2 评论 0原文

这是我收到的错误

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(24

So要识趣 2024-10-27 02:36:40

您的系统上似乎缺少 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
段念尘 2024-10-27 02:36:40

在 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)

苏辞 2024-10-27 02:36:40

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

对于 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
守不住的情 2024-10-27 02:36:40
apt-get install libmysqlclient-dev python-dev

似乎成功了。

apt-get install libmysqlclient-dev python-dev

Seemed to do the trick.

箹锭⒈辈孓 2024-10-27 02:36:40

如果您使用的是 MAC
全局安装这个

brew install mysql

然后像这样导出路径

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

比全局或在你的venv中无论你喜欢什么

pip install MySQL-Python

注意:对于python3全局,因为Mac可以同时拥有python2和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
oО清风挽发oО 2024-10-27 02:36:40

您可以使用 MySQL Connector/Python

通过 PyPip 安装

pip install mysql-connector-python

更多信息可以在 MySQL 连接器/Python 1.0.5 beta 公告 博客。

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

You can use the MySQL Connector/Python

Installation via PyPip

pip install mysql-connector-python

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.

蓝海似她心 2024-10-27 02:36:40

对于 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

若能看破又如何 2024-10-27 02:36:40

我试图在 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

这就成功了。

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.

小鸟爱天空丶 2024-10-27 02:36:40

对于使用 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
西瑶 2024-10-27 02:36:40

对于 Linux

这对我有用

yum install python-devel mysql-devel

For Linux

this works for me

yum install python-devel mysql-devel
半葬歌 2024-10-27 02:36:40

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

Try sudo apt-get build-dep python-mysqldb

稀香 2024-10-27 02:36:40

OSX Mavericks

由于 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

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
摘星┃星的人 2024-10-27 02:36:40

对于 mariadb,安装 libma​​riadbclient-dev 而不是 libmysqlclient-dev

sudo apt-get install libmariadbclient-dev

for mariadb install libmariadbclient-dev instead of libmysqlclient-dev

sudo apt-get install libmariadbclient-dev
喜爱纠缠 2024-10-27 02:36:40

我在 Terraform:light 容器中遇到了同样的问题。它基于 Alpine。

在那里你必须安装 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
想你只要分分秒秒 2024-10-27 02:36:40

您应该先安装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
萌能量女王 2024-10-27 02:36:40

有时错误取决于实际原因。我们有一个例子,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 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.

这个俗人 2024-10-27 02:36:40

应遵循的顺序。

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

夕嗳→ 2024-10-27 02:36:40

在 Mac 上:

brew install mysql-client

找到 mysql

mdfind mysql | grep bin

然后添加到路径

export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/

或永久添加

echo "export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/" >> ~/.zshrc
source ~/.zshrc

On Mac:

brew install mysql-client

locate mysql

mdfind mysql | grep bin

then add to path

export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/

or permanently

echo "export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/" >> ~/.zshrc
source ~/.zshrc
栀梦 2024-10-27 02:36:40

尝试在 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

现在 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:

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 :-)

三月梨花 2024-10-27 02:36:40

您的 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.

执笔绘流年 2024-10-27 02:36:40

如果你在虚拟环境中安装了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
御弟哥哥 2024-10-27 02:36:40

就我而言,我的数据库在容器上运行,而我的 Flask 应用程序在另一个容器上运行,当我尝试更新代码时,应用程序因错误而中断,

   Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-bya8e734/mysqlclient/setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 65, in get_config
    libs = mysql_config("libs")
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 31, in mysql_config
    raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found

堆栈跟踪中的密钥是

/bin/sh: 1: mysql_config: not found

因为我的 Flask 应用程序运行的地方没有正确配置 mysql 客户端,所以首先我安装了mysql服务器,然后安装

sudo apt-get install mysql-server-5.7 -y

然后启动MySQL

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo systemctl start mysql

然后安装flask-mysql包,这次它工作了

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo pip3 install flask-mysqldb

这是不同的情况,但在这里发布,因为世界上可能有其他人面临同样的问题

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

   Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-bya8e734/mysqlclient/setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 65, in get_config
    libs = mysql_config("libs")
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 31, in mysql_config
    raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found

Key in stack trace is

/bin/sh: 1: mysql_config: not found

because where my flask app is running doesn't have mysql client properly configured so first i installed mysql server and then install

sudo apt-get install mysql-server-5.7 -y

Then started MySQL

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo systemctl start mysql

Then install flask-mysql package and this time it worked

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo pip3 install flask-mysqldb

This is different case but posting here because may be someone else in the world facing same issue

泛泛之交 2024-10-27 02:36:40

写于2021年8月27日,

我的macos版本是BigSur(14.4),mysql版本是mysql8。似乎在更高版本的mysql中,他们删除了my_config.h文件,但更改为mysql.h

所以你们应该运行以下 shell:

cd /usr/local/include/mysql
cp mysql.h my_config.h

之后,运行 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 the mysql.h.

so your guys should run the following shell:

cd /usr/local/include/mysql
cp mysql.h my_config.h

after that, run pip install MySQL-python and everything will be ok.

浅笑轻吟梦一曲 2024-10-27 02:36:40

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文