安装mysqldb python界面时找不到mysql_config
我正在尝试让 Python 脚本在我通过 ssh 连接的 Linux 服务器上运行。该脚本使用 mysqldb。我拥有所需的所有其他组件,但是当我尝试通过 setuptools 安装 mySQLdb 时,如下所示:,
python setup.py install
我收到以下与 mysql_config 命令相关的错误报告。
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
有其他人遇到过这个错误吗?如果是的话,你是如何解决它的/我该怎么做才能成功安装 mysqldb?
I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:,
python setup.py install
I get the following error report related to the mysql_config
command.
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Has anyone else encountered this error and if so how did you resolve it/what can I do to successfully install mysqldb?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
在 python 3.5.2 + 任何未来版本上
sudo apt-get install libmysqlclient-dev python-dev
On python 3.5.2 + any future version
sudo apt-get install libmysqlclient-dev python-dev
以下内容在 Ubuntu 12.04 LTS 上对我有用:
尽管它有效,但我仍然继续执行以下操作:
The below worked for me on Ubuntu 12.04 LTS:
All though it worked, i still went ahead to do the below:
我在尝试安装 mysql-python 时遇到了同样的错误。
我就是这样解决的。
问题是安装程序在默认路径中找不到 mysql_config。现在它可以..并且有效..
希望这会有所帮助。
谢谢。
I got the same error while trying to install
mysql-python
.This is how I fixed it.
The problem was that the installer could not find the mysql_config in the default path. Now it can ..and it worked..
Hope this helps.
Thanks.
我通过以下步骤解决了这个问题:
I fixed this problem with the following steps:
命令(mysql 也是如此)mPATH 可能丢失。
导出PATH=$PATH:/usr/local/mysql/bin/
The commands (mysql too) mPATH might be missing.
export PATH=$PATH:/usr/local/mysql/bin/
Step1:-安装Python3 & Python3-dev 两者
第2步:- 安装Python和Python3-dev两者 Mysql 连接器
步骤3:- 安装 python mysql 客户端
这将解决您的问题
Step1:-Install Python3 & Python3-dev Both
Step2:- Install Python & Mysql Connector
step3:- Install python mysql client
This will Solve your Problem
libmysqlclient-dev 软件包已被弃用,因此请使用以下命令来修复它。
软件包 libmysqlclient-dev 不可用,但被另一个软件包引用。
这可能意味着该包丢失、已过时或
只能从其他来源获得
The package libmysqlclient-dev is deprecated, so use the below command to fix it.
Package libmysqlclient-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
我认为 2020 年解决这个问题最方便的方法是使用另一个 python 包。我们不需要安装任何其他二进制软件。
试试这个
pip install mysql-connector-python
然后
I think the most convenient way to solve this problem in 2020 is using another python package. We don't need install any other binary software.
Try this
pip install mysql-connector-python
and then
如果您使用的是 macOS 并且已通过 brew install 安装了[email protected] :
brew install mysql-connector-c
brew unlink [电子邮件受保护]
brew 链接 --overwrite --空运行 [email protected]
首先,查看哪些符号链接被覆盖brew link --overwrite --force [email protected]
实际上用 [电子邮件受保护]pip install mysqlclient
If you're on macOS and already installed [email protected] via brew install:
brew install mysql-connector-c
brew unlink [email protected]
brew link --overwrite --dry-run [email protected]
first, to see what symlinks are getting overwrittenbrew link --overwrite --force [email protected]
to actually overwrite mysql-related symlinks with [email protected]pip install mysqlclient
我通过安装 libmysqlclient 修复了它:
I fixed it by installing libmysqlclient:
在 centos 7 中,这对我有用:
In centos 7 this works for me :
MySQL-python
包使用mysql_config
命令来了解主机上的mysql
配置。您的主机没有 mysql_config 命令。dev.mysql.com 的 MySQL 开发库包 (MySQL-devel-xxx) 提供了此命令以及 MySQL-python 包所需的库。
MySQL-devel
软件包可在下载 - 社区服务器区域中找到。 MySQL开发库包名称以MySQL-devel
开头,并根据MySQL版本和Linux平台而有所不同(例如MySQL-devel-5.5.24-1.linux2.6.x86_64.rpm
code>.)请注意,您不需要安装 mysql 服务器。
The
MySQL-python
package is using themysql_config
command to learn about themysql
configuration on your host. Your host does not have themysql_config
command.The MySQL development libraries package (MySQL-devel-xxx) from dev.mysql.com provides this command and the libraries needed by the MySQL-python package. The
MySQL-devel
packages are found in the download - community server area. The MySQL development library package names start withMySQL-devel
and vary based MySQL version and linux platform (e.g.MySQL-devel-5.5.24-1.linux2.6.x86_64.rpm
.)Note that you do not need to install mysql server.
对于 Alpine Linux:
$ apk add mariadb-dev mariadb-client mariadb-libs
MariaDB 是一个 MySQL 的直接替代品 并成为 Alpine 3.2 的新标准。请参阅https://bugs.alpinelinux.org/issues/4264
For Alpine Linux:
$ apk add mariadb-dev mariadb-client mariadb-libs
MariaDB is a drop-in replacement for MySQL and became the new standard as of Alpine 3.2. See https://bugs.alpinelinux.org/issues/4264
在我的 Fedora 23 机器上,我必须运行以下命令:
On my Fedora 23 machine I had to run the following:
在 CentOS 7 中,应该执行以下操作:
或
In CentOS 7 , the following things should be done:
or
另外,我也遇到了同样的问题
我通过以下步骤解决了这个问题:
首先我运行这个命令
,然后安装
这对我有用
also, i fetch the same problem
I fixed this problem with the following steps:
First I run this command
then I install
this is worked for me
我认为,可以在终端上执行以下几行
。此 mysql_config 目录适用于 MacOSx 上的 zend 服务器。你可以像下面的代码那样为 Linux 执行此操作
This is default linux mysql directory。
I think, following lines can be executed on terminal
This mysql_config directory is for zend server on MacOSx. You can do it for linux like following lines
This is default linux mysql directory.
我遇到了这个问题,并通过向 mysql_config 添加符号链接来解决。
我已经用 homebrew 安装了 mysql,并在输出中看到了这一点。
根据您获取 mysql 的方式,它将位于不同的位置。就我而言
/usr/local/Cellar/mysql
一旦你知道它在哪里,你应该能够建立一个符号链接到Python正在寻找它的地方。
/usr/local/mysql
这对我有用。
I had this issues and solved if by adding a symlink to
mysql_config
.I had installed mysql with homebrew and saw this in the output.
Depending on how you got
mysql
it will be in different places. In my case/usr/local/Cellar/mysql
Once you know where it is you should be able to ma a symbolic link to where python is looking for it.
/usr/local/mysql
This worked for me.
我也有同样的问题。我按照 本教程在 Ubuntu 16.04 上使用 python3-dev 安装 Python:
现在您可以设置虚拟环境:
I had the same problem. I solved it by following this tutorial to install Python with python3-dev on Ubuntu 16.04:
And now you can set up your virtual environment:
您需要安装 python-dev 包:
You need to install the python-dev package:
sudo apt-get install python-mysqldb
Python 2.5?听起来您使用的是非常旧版本的 Ubuntu Server(Hardy 8.04?) - 请确认服务器使用哪个 Linux 版本。
ubuntu 软件包数据库上的 python-mysql 搜索< /a>
一些附加信息:
的自述文件
来自 mysql-python - Red Hat Linux
......
MySQL-python 已预打包在 Red Hat Linux 7.x 及更高版本中。这
包括 Fedora Core 和 Red Hat Enterprise Linux。您还可以
如上所述构建您自己的 RPM 包。
Debian GNU/Linux
................
打包为
python-mysqldb
_::或者使用 Synaptic。
.. _
python-mysqldb
: http://packages.debian.org/python -mysqldbUbuntu
......
与 Debian 相同。
脚注:如果您确实使用早于 Ubuntu 10.04 的服务器发行版,那么您将不再获得官方支持,并且应该尽早升级。
sudo apt-get install python-mysqldb
Python 2.5? Sounds like you are using a very old version of Ubuntu Server (Hardy 8.04?) - please confirm which Linux version the server uses.
python-mysql search on ubuntu package database
Some additional info:
From the README of mysql-python -
Red Hat Linux
.............
MySQL-python is pre-packaged in Red Hat Linux 7.x and newer. This
includes Fedora Core and Red Hat Enterprise Linux. You can also
build your own RPM packages as described above.
Debian GNU/Linux
................
Packaged as
python-mysqldb
_::Or use Synaptic.
.. _
python-mysqldb
: http://packages.debian.org/python-mysqldbUbuntu
......
Same as with Debian.
Footnote: If you really are using a server distribution older than Ubuntu 10.04 then you are out of official support, and should upgrade sooner rather than later.
此方法仅适用于那些知道Mysql已安装但仍找不到mysql_config的人。如果 python install 在系统路径中找不到 mysql_config,就会发生这种情况,如果您通过 .dmg Mac Package 完成安装或安装在某个自定义路径,则通常会发生这种情况。 MySqlDB 最简单且有记录的方法是更改 site.cfg。找到可能位于 /usr/local/mysql/bin/ 中的 mysql_config 并更改变量 mysql_config ,如下所示,然后再次运行安装。不要忘记通过删除“#”来取消注释,
更改以下行
到
取决于系统中的路径。
顺便说一句,我在更改 site.cfg
sudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py install后使用了 python install
This method is only for those who know that Mysql is installed but still mysql_config can't be find. This happens if python install can't find mysql_config in your system path, which mostly happens if you have done the installation via .dmg Mac Package or installed at some custom path. The easiest and documented way by MySqlDB is to change the site.cfg. Find the mysql_config which is probably in /usr/local/mysql/bin/ and change the variable namely mysql_config just like below and run the installation again. Don't forget to un-comment it by removing "#"
Change below line
to
depending upon the path in your system.
By the way I used python install after changing the site.cfg
sudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py install
只需输入:
这将解决这个问题。
Just type:
This will solve this problems.
到目前为止,所有解决方案 (Linux) 都需要
sudo
或 root 权限才能安装。如果您没有root权限并且没有
sudo
,这里有一个解决方案。 (没有sudo apt install ...
):dpkg -x libmysqlclient-dev_.deb .
这将提取一个名为usr
的文件夹。将
./usr/bin/mysql_config
符号链接到$PATH
上的某个位置:ln -s
`pwd`
/usr/bin/mysql_config FOLDER_IN_YOUR_PATH
现在应该能够找到
mysql_config
在 Ubuntu 18.04 上测试。
So far, all solutions (Linux) require
sudo
or root rights to install .Here is a solution if you do not have root rights and without
sudo
. (nosudo apt install ...
):dpkg -x libmysqlclient-dev_<version tag>.deb .
This will extract a folder calledusr
.Symlink
./usr/bin/mysql_config
to somewhere that is found on your$PATH
:ln -s
`pwd`
/usr/bin/mysql_config FOLDER_IN_YOUR_PATH
It should now be able to find
mysql_config
Tested on Ubuntu 18.04.
对于 macOS Mojave ,需要额外的配置,为了让编译器找到 openssl ,您可能需要设置:
For macOS Mojave , additional configuration was required, for compilers to find openssl you may need to set:
在 MacOS (OS/X) Catalina 上,我发现我需要执行以下操作:
在我的计算机上,
mysql
命令位于/usr/local/bin
(来自标准 MacOS 安装程序,而不是“brew”)。On MacOS (OS/X) Catalina, I found that I needed to do this:
On my computer, the
mysql
command is in/usr/local/bin
(from the standard MacOS installer, not "brew").mySQLdb 是 mysql 的 python 接口,但它不是 mysql 本身。显然 mySQLdb 需要命令“mysql_config”,因此您需要先安装它。
您能否通过从 shell 运行“mysql”来确认您是否安装了 mysql 本身?这应该给你一个除了“mysql:命令未找到”之外的响应。
您使用的是哪个 Linux 发行版? Mysql 已针对大多数 Linux 发行版进行了预打包。例如,对于 debian / ubuntu,安装 mysql 很简单,因为
mysql-config 位于不同的包中,可以从以下位置安装(再次假设 debian / ubuntu):
如果您使用 mariadb,则可以替换 mysql,然后运行
参考:
https://github.com/JudgeGirl/Judge-sender/issues/4 #issuecomment-186542797
mySQLdb is a python interface for mysql, but it is not mysql itself. And apparently mySQLdb needs the command 'mysql_config', so you need to install that first.
Can you confirm that you did or did not install mysql itself, by running "mysql" from the shell? That should give you a response other than "mysql: command not found".
Which linux distribution are you using? Mysql is pre-packaged for most linux distributions. For example, for debian / ubuntu, installing mysql is as easy as
mysql-config is in a different package, which can be installed from (again, assuming debian / ubuntu):
if you are using mariadb, the drop in replacement for mysql, then run
Reference:
https://github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797
我在 Ubuntu 12.04 上安装
python-mysql
首先我遇到了同样的问题:
这对我有用
然后我遇到了这个问题:
然后我尝试使用
(如果您使用的是 python3,请安装
python3-dev 代替。)
然后我很高兴:)
I was installing
python-mysql
on Ubuntu 12.04 usingFirst I had the same problem:
This worked for me
Then I had this problem:
Then I tried with
(If you're using python3, install
python3-dev
instead.)And then I was happy :)
(特定于Mac OS X)
我尝试了很多东西,但是这组命令最终对我有用。
brew unlink mysql
brew install mysql-connector-c
mkdir /usr/local/Cellar/lib/
brew 重新安装 openssl
(来源):
如果这不起作用,@vinyll 建议在步骤 8 之前运行
brew link mysql
。(Specific to Mac OS X)
I have tried a lot of things, but these set of commands finally worked for me.
mysql
brew unlink mysql
brew install mysql-connector-c
mkdir /usr/local/Cellar/lib/
brew reinstall openssl
(source)Update:
In case this doesn't work, @vinyll suggests to run
brew link mysql
before step 8.在红帽上我必须这样做
然后它就起作用了。
On Red Hat I had to do
Then it worked.