问题:安装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?
回答 0
mySQLdb是mysql的python接口,但不是mysql本身。显然,mySQLdb需要命令“ mysql_config”,因此您需要先安装该命令。
您可以通过从shell运行“ mysql”来确认自己是否安装了mysql吗?这应该给您一个响应,而不是“ mysql:not found”。
您使用的是哪个Linux发行版?Mysql已为大多数Linux发行版预先打包。例如,对于debian / ubuntu,安装mysql就像
sudo apt-get install mysql-server
mysql-config位于不同的软件包中,可以从安装(同样,假设debian / ubuntu):
sudo apt-get install libmysqlclient-dev
如果您使用的是mariadb,请替换为mysql,然后运行
sudo apt-get install libmariadbclient-dev
参考: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
sudo apt-get install mysql-server
mysql-config is in a different package, which can be installed from (again, assuming debian / ubuntu):
sudo apt-get install libmysqlclient-dev
if you are using mariadb, the drop in replacement for mysql, then run
sudo apt-get install libmariadbclient-dev
Reference:
https://github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797
回答 1
我正在python-mysql
使用以下命令在Ubuntu 12.04上安装
pip install mysql-python
首先,我有同样的问题:
Not Found "mysql_config"
这对我有用
$ sudo apt-get install libmysqlclient-dev
然后我有这个问题:
...
_mysql.c:29:20: error fatal: Python.h: No existe el archivo o el directorio
compilación terminada.
error: command 'gcc' failed with exit status 1
然后我尝试了
apt-get install python-dev
然后我很高兴:)
pip install mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g
In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:422:0: aviso: se redefinió "HAVE_WCSCOLL" [activado por defecto]
/usr/include/python2.7/pyconfig.h:890:0: nota: esta es la ubicación de la definición previa
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
Successfully installed mysql-python
Cleaning up...
I was installing python-mysql
on Ubuntu 12.04 using
pip install mysql-python
First I had the same problem:
Not Found "mysql_config"
This worked for me
$ sudo apt-get install libmysqlclient-dev
Then I had this problem:
...
_mysql.c:29:20: error fatal: Python.h: No existe el archivo o el directorio
compilación terminada.
error: command 'gcc' failed with exit status 1
Then I tried with
apt-get install python-dev
And then I was happy :)
pip install mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g
In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:422:0: aviso: se redefinió "HAVE_WCSCOLL" [activado por defecto]
/usr/include/python2.7/pyconfig.h:890:0: nota: esta es la ubicación de la definición previa
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
Successfully installed mysql-python
Cleaning up...
回答 2
(特定于Mac OS X)
我做了很多尝试,但是这些命令最终对我有用。
- 安装
mysql
brew install mysql
brew unlink mysql
brew install mysql-connector-c
- 将mysql bin文件夹添加到PATH
export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH
mkdir /usr/local/Cellar/lib/
- 创建一个符号链接
sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib
brew reinstall openssl
(来源)
- 最后,安装mysql-client
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient
更新:如果此方法不起作用,@ vinyll建议brew link mysql
在步骤8之前运行。
(Specific to Mac OS X)
I have tried a lot of things, but these set of commands finally worked for me.
- Install
mysql
brew install mysql
brew unlink mysql
brew install mysql-connector-c
- Add the mysql bin folder to PATH
export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH
mkdir /usr/local/Cellar/lib/
- Create a symlink
sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib
brew reinstall openssl
(source)
- Finally, install mysql-client
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient
Update:
In case this doesn’t work, @vinyll suggests to run brew link mysql
before step 8.
回答 3
在红帽上,我不得不做
sudo yum install mysql-devel gcc gcc-devel python-devel
sudo easy_install mysql-python
然后它起作用了。
On Red Hat I had to do
sudo yum install mysql-devel gcc gcc-devel python-devel
sudo easy_install mysql-python
Then it worked.
回答 4
以下内容适用于Ubuntu 12.04 LTS:
apt-get install libmysqlclient-dev python-dev
尽管一切正常,但我仍然继续执行以下操作:
export PATH=$PATH:/usr/local/mysql/bin/
The below worked for me on Ubuntu 12.04 LTS:
apt-get install libmysqlclient-dev python-dev
All though it worked, i still went ahead to do the below:
export PATH=$PATH:/usr/local/mysql/bin/
回答 5
尝试安装时出现相同的错误mysql-python
。
这就是我修复它的方式。
sudo PATH=/usr/local/mysql/bin/:$PATH pip install mysql-python
问题是安装程序无法在默认路径中找到mysql_config。现在它可以..并且有效..
15 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.8-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc -o build/lib.macosx-10.8-intel-2.7/_mysql.so -arch x86_64
Successfully installed mysql-python
Cleaning up...
希望这可以帮助。
谢谢。
I got the same error while trying to install mysql-python
.
This is how I fixed it.
sudo PATH=/usr/local/mysql/bin/:$PATH pip install mysql-python
The problem was that the installer could not find the mysql_config in the default path. Now it can ..and it worked..
15 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.8-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc -o build/lib.macosx-10.8-intel-2.7/_mysql.so -arch x86_64
Successfully installed mysql-python
Cleaning up...
Hope this helps.
Thanks.
回答 6
我通过以下步骤解决了此问题:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install
I fixed this problem with the following steps:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install
回答 7
命令(也是mysql)mPATH可能丢失。
export PATH=$PATH:/usr/local/mysql/bin/
The commands (mysql too) mPATH might be missing.
export PATH=$PATH:/usr/local/mysql/bin/
回答 8
步骤1:-同时安装Python3和Python3-dev
sudo apt-get install python3 python3-dev
步骤2:- 安装Python和Mysql连接器
sudo apt-get install libmysqlclient-dev
步骤3:- 安装python mysql客户端
sudo apt-get install mysqlclient
这将解决您的问题
Step1:-Install Python3 & Python3-dev Both
sudo apt-get install python3 python3-dev
Step2:- Install Python & Mysql Connector
sudo apt-get install libmysqlclient-dev
step3:- Install python mysql client
sudo apt-get install mysqlclient
This will Solve your Problem
回答 9
如果您使用的是macOS,并且已经通过brew install安装了mysql@5.7,请执行以下操作:
brew install mysql-connector-c
brew unlink mysql@5.7
brew link --overwrite --dry-run mysql@5.7
首先,查看哪些符号链接被覆盖
brew link --overwrite --force mysql@5.7
用mysql@5.7实际覆盖与mysql相关的符号链接
pip install mysqlclient
If you’re on macOS and already installed mysql@5.7 via brew install:
brew install mysql-connector-c
brew unlink mysql@5.7
brew link --overwrite --dry-run mysql@5.7
first, to see what symlinks are getting overwritten
brew link --overwrite --force mysql@5.7
to actually overwrite mysql-related symlinks with mysql@5.7
pip install mysqlclient
回答 10
我通过安装libmysqlclient来修复它:
sudo apt-get install libmysqlclient16-dev
I fixed it by installing libmysqlclient:
sudo apt-get install libmysqlclient16-dev
回答 11
该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
)为基础,并有所不同。
注意,您不需要安装mysql服务器。
The MySQL-python
package is using the mysql_config
command to learn about the mysql
configuration on your host. Your host does not have the mysql_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 with MySQL-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.
回答 12
不建议使用libmysqlclient-dev软件包,因此请使用以下命令对其进行修复。
软件包libmysqlclient-dev不可用,但是由另一个软件包引用。这可能意味着该软件包已丢失,已被废弃或只能从其他来源获得
sudo apt-get install default-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
sudo apt-get install default-libmysqlclient-dev
回答 13
在centos 7中,这对我有用:
yum install mariadb-devel
pip install mysqlclient
In centos 7 this works for me :
yum install mariadb-devel
pip install mysqlclient
回答 14
在我的Fedora 23机器上,我必须运行以下命令:
sudo dnf install mysql-devel
On my Fedora 23 machine I had to run the following:
sudo dnf install mysql-devel
回答 15
回答 16
我认为,以下几行可以在终端上执行
sudo ln -s /usr/local/zend/mysql/bin/mysql_config /usr/sbin/
该mysql_config目录用于MacOSx上的zend服务器。您可以像下面的几行一样在linux上做
sudo ln -s /usr/local/mysql/bin/mysql_config /usr/sbin/
这是默认的Linux mysql目录。
I think, following lines can be executed on terminal
sudo ln -s /usr/local/zend/mysql/bin/mysql_config /usr/sbin/
This mysql_config directory is for zend server on MacOSx. You can do it for linux like following lines
sudo ln -s /usr/local/mysql/bin/mysql_config /usr/sbin/
This is default linux mysql directory.
回答 17
我遇到了这个问题,并通过将符号链接添加到来解决mysql_config
。
我已经用自制软件安装了mysql,并在输出中看到了这一点。
Error: The `brew link` step did not complete successfully
根据您的购买方式,mysql
它会出现在不同的地方。以我为例,/usr/local/Cellar/mysql
一旦您知道它在哪里,就应该可以建立一个指向python寻找位置的符号链接。 /usr/local/mysql
这对我有用。
ln -s /usr/local/Cellar/mysql/<< VERSION >>/bin/mysql_config /usr/local/mysql/bin/mysql_config
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.
Error: The `brew link` step did not complete successfully
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.
ln -s /usr/local/Cellar/mysql/<< VERSION >>/bin/mysql_config /usr/local/mysql/bin/mysql_config
回答 18
我有同样的问题。我通过按照本教程在Ubuntu 16.04上使用python3-dev安装Python的方式解决了该问题:
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
现在您可以设置虚拟环境:
sudo apt-get install -y python3-venv
pyvenv my_env
source my_env/bin/activate
I had the same problem. I solved it by following this tutorial to install Python with python3-dev on Ubuntu 16.04:
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
And now you can set up your virtual environment:
sudo apt-get install -y python3-venv
pyvenv my_env
source my_env/bin/activate
回答 19
您需要安装python-dev软件包:
sudo apt-get install python-dev
You need to install the python-dev package:
sudo apt-get install python-dev
回答 20
须藤apt-get install python-mysqldb
Python 2.5?听起来您正在使用非常旧的Ubuntu Server版本(Hardy 8.04?)-请确认服务器使用的Linux版本。
在ubuntu软件包数据库上搜索python-mysql
一些其他信息:
从mysql-python的自述文件-
红帽Linux ………….
MySQL-python已预包装在Red Hat Linux 7.x和更高版本中。这包括Fedora Core和Red Hat Enterprise Linux。您还可以如上所述构建自己的RPM软件包。
Debian GNU / Linux …………….
打包为python-mysqldb
_ ::
# apt-get install python-mysqldb
或使用Synaptic。
.. _ python-mysqldb
:http : //packages.debian.org/python-mysqldb
Ubuntu ……
与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
_::
# apt-get install python-mysqldb
Or use Synaptic.
.. _python-mysqldb
: http://packages.debian.org/python-mysqldb
Ubuntu
……
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.
回答 21
该方法仅适用于那些知道已安装Mysql但仍找不到mysql_config的用户。如果python安装无法在系统路径中找到mysql_config,则会发生这种情况,如果通过.dmg Mac Package完成安装或在某个自定义路径中进行安装,则通常会发生这种情况。MySqlDB最简单且记录在案的方法是更改site.cfg。找到可能位于/ usr / local / mysql / bin /中的mysql_config,然后像下面那样更改变量mysql_config,然后再次运行安装。不要忘记通过删除“#”取消注释
在行下更改
“ #mysql_config = / usr / local / bin / mysql_config”
至
“ mysql_config = / usr / local / mysql / bin / mysql_config”
取决于系统中的路径。
顺便说一句,我在更改site.cfg之后使用python安装
sudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py安装
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
“#mysql_config = /usr/local/bin/mysql_config”
to
“mysql_config = /usr/local/mysql/bin/mysql_config”
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
回答 22
到目前为止,所有解决方案(Linux)都需要具有sudo
root用户权限才能安装。如果您没有root权限且没有root权限,则这是一个解决方案sudo
。(否sudo apt install ...
):
- 从此镜像下载libmysqlclient-dev的.deb文件
- 导航到下载的文件并运行。
dpkg -x libmysqlclient-dev_<version tag>.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
. (no sudo apt install ...
):
- Download the .deb file of the libmysqlclient-dev, e.g. from this mirror
- Navigate to the downloaded file and run
dpkg -x libmysqlclient-dev_<version tag>.deb .
This will extract a folder called usr
.
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.
回答 23
对于macOS Mojave,需要附加配置,编译器才能找到openssl,您可能需要设置:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
For macOS Mojave , additional configuration was required, for compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
回答 24
我认为在2020年解决此问题的最便捷方法是使用另一个python软件包。我们不需要安装任何其他二进制软件。
尝试这个
pip install mysql-connector-python
然后
import mysql.connector
mydb = mysql.connector.connect(
host="",
user="",
passwd="",
database=""
)
cursor = mydb.cursor( buffered=True)
cursor.execute('show tables;')
cursor.execute('insert into test values (null, "a",10)')
mydb.commit()
mydb.disconnect()
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
import mysql.connector
mydb = mysql.connector.connect(
host="",
user="",
passwd="",
database=""
)
cursor = mydb.cursor( buffered=True)
cursor.execute('show tables;')
cursor.execute('insert into test values (null, "a",10)')
mydb.commit()
mydb.disconnect()
回答 25
我遇到了同样的问题,只是将* mysql_config *所在的路径添加到环境变量PATH中,它对我有用。
I encountered the same problem, just added the path where *mysql_config* resided to the environment variable PATH and it worked for me.
回答 26
sudo apt-get build-dep python-mysqldb
将安装所有依赖项以从PIP / easy_install构建软件包
sudo apt-get build-dep python-mysqldb
will install all the dependencies to build the package from PIP/easy_install
回答 27
由于实际错误是
gcc ... -I/usr/include/python2.7 ...
_mysql.c:29:20: error: Python.h: No such file or directory
并且如果您无法安装python-dev或python-devel软件包,则可以从http://hg.python.org/下载包含所需版本的python源的存档,并将标头文件放置在正确的文件夹中,以包含
As actual error is
gcc ... -I/usr/include/python2.7 ...
_mysql.c:29:20: error: Python.h: No such file or directory
and If you can’t install python-dev or python-devel packages, you may download archive with needed version of python sources from http://hg.python.org/ and place headers files in proper folder for include
回答 28
只需输入:
$ sudo apt-get install python-dev
$ venv/bin/pip install MySQL-python
这样可以解决这个问题。
Just type:
$ sudo apt-get install python-dev
$ venv/bin/pip install MySQL-python
This will solve this problems.
回答 29
在CentOS 7中,应执行以下操作:
#step1:install mysql
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
#step2:
sudo yum install mysql-devel
In CentOS 7 , the following things should be done:
#step1:install mysql
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
#step2:
sudo yum install mysql-devel