我试图让一个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?
答案 0 :(得分:570)
mySQLdb是mysql的python接口,但它不是mysql本身。显然mySQLdb需要命令'mysql_config',所以你需要先安装它。
你可以通过从shell运行“mysql”来确认你是否安装了mysql本身?这应该给你一个响应,而不是“mysql:command 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
答案 1 :(得分:169)
我正在使用
在Ubuntu 12.04上安装python-mysql
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...
答案 2 :(得分:30)
以下在Ubuntu 12.04 LTS上为我工作:
apt-get install libmysqlclient-dev python-dev
尽管它起作用,我仍然继续做下面的事情:
export PATH=$PATH:/usr/local/mysql/bin/
答案 3 :(得分:28)
在Red Hat上我必须做
sudo yum install mysql-devel gcc gcc-devel python-devel
sudo easy_install mysql-python
然后它奏效了。
答案 4 :(得分:23)
我在尝试安装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...
希望这有帮助。
感谢。
答案 5 :(得分:18)
我通过以下步骤解决了这个问题:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install
答案 6 :(得分:17)
命令(也是mysql)mPATH可能会丢失。
export PATH=$PATH:/usr/local/mysql/bin/
答案 7 :(得分:16)
在python 3.5.2上
class DeliveryInfoFragment : Fragment() {
lateinit var order: Order
companion object {
fun instantiate(order: Order): DeliveryInfoFragment {
val fragment = DeliveryInfoFragment()
fragment.order = order
return fragment
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
.....
.....
}
override fun onResume() {
super.onResume()
order.addChangeListener(
RealmObjectChangeListener<Order> { _, _ ->
if (isVisible)
setupUI()
}
)
}
override fun onDestroy() {
super.onDestroy()
if (isVisible)
order.removeAllChangeListeners()
}
答案 8 :(得分:15)
不建议使用libmysqlclient-dev软件包,因此请使用以下命令对其进行修复。
软件包libmysqlclient-dev不可用,但是被另一个软件包引用。 这可能意味着包裹丢失,已被废弃或 只能从其他来源获得
sudo apt-get install default-libmysqlclient-dev
答案 9 :(得分:10)
(特定于Mac)我已经尝试了很多事情,但是这些命令最终对我有用。
brew install mysql
#安装mysql brew unlink mysql
brew install mysql-connector-c
export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH
#更新路径并将mysql bin文件夹设置为path sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib
#创建符号链接pip install mysqlclient
#最终安装mysql-client 答案 10 :(得分:8)
我认为在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()
答案 11 :(得分:8)
第一步:-同时安装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
这将解决您的问题
答案 12 :(得分:8)
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服务器。
答案 13 :(得分:8)
我通过安装libmysqlclient来修复它:
sudo apt-get install libmysqlclient16-dev
答案 14 :(得分:5)
如果您使用的是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
答案 15 :(得分:5)
在centos 7中,这对我有用:
System.IO.Path.GetFileName(DrawingName);
答案 16 :(得分:5)
在我的Fedora 23机器上,我必须执行以下操作:
sudo dnf install mysql-devel
答案 17 :(得分:5)
对于Alpine Linux:
$ apk add mariadb-dev mariadb-client mariadb-libs
MariaDB是drop-in replacement for MySQL,并成为Alpine 3.2的新标准。见https://bugs.alpinelinux.org/issues/4264
答案 18 :(得分:4)
我认为,可以在终端上执行以下行
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目录。
答案 19 :(得分:4)
我遇到了这个问题并通过向{
"@timestamp": "27-11-2015 21:31:30 PM", "thingstodo": [{
"propCode": "foo1"
},
{
"propCode": "foo2"
},
{
"propCode": "foo3",
"hours": [{
"day": "Monday-Thursday",
"time": "2:00PM - 1:00AM"
},
{
"day": "Friday-Sunday",
"time": "10:00AM - 2:00AM"
}]
},
{
"propCode": "foo4"
},
{
"propCode": "foo5",
"hours": [{
"day": "Daily",
"time": "24 Hours"
}]
},
{
"propCode": "foo6",
"hours": [{
"day": "10am - 4am",
"time": "bar & lounge area"
},
{
"day": "12pm - 4am",
"time": "gaming area"
}]
},
{
"propCode": "foo7",
"hours": [{
"day": "Daily",
"time": "11:00AM - 1:00AM"
},
{
"day": "Happy Hour Daily",
"time": "4:00PM - 6:00PM"
}]
},
{
"propCode": "foo8"
},
{
"propCode": "foo9"
},
{
"propCode": "foo10",
"hours": [{
"day": "Sun-Thu",
"time": "10:00AM - 11:00PM"
},
{
"day": "Fri & Sat",
"time": "10:00AM - 12:00AM"
}]
},
{
"propCode": "foo11",
"name": "Atlantic City Deals and Packages",
"brand": "harrahs"
},
{
"propCode": "foo12"
},
{
"propCode": "foo13",
"hours": [{
"day": "Sun-Thu",
"time": "11:00AM - 1:00AM"
},
{
"day": "Fri-Sat",
"time": "11:00AM - 2:00AM"
}]
},
{
"propCode": "foo8",
"hours": [{
"day": "Daily",
"time": "11:00AM - 2:00AM"
}]
},
{
"propCode": "foo12"
},
{
"propCode": "foo14"
},
{
"propCode": "foo14",
"hours": [{
"day": "Daily",
"time": "6:00AM - 6:00PM"
}]
},
{
"propCode": "foo12",
"hours": [{
"day": "Sunday-Thursday",
"time": "8:00AM - 6:00PM"
},
{
"day": "Friday-Saturday",
"time": "8:00AM - 7:00PM<br>"
},
{
"day": "<br>Adult Swim (21+)<br> Sunday-Thursday",
"time": "5:00PM - 6:00PM"
},
{
"day": "Friday-Saturday",
"time": "5:00PM - 7:00PM"
}]
},
{
"propCode": "foo15",
"hours": [{
"day": "Mon-Thu ",
"time": "9:00AM - 9:30PM
"
},
{
"day": "Fri-Sun ",
"time": "9:00AM - Midnight"
}]
},
{
"propCode": "foo16",
"hours": [{
"day": "Sun - Thurs:",
"time": "9:00AM - 5:00PM"
},
{
"day": "Fri - Sat:",
"time": "9:00AM - 6:00PM"
},
{
"day": "Slide",
"time": "Closed for the season"
}]
},
{
"propCode": "foo17",
"hours": [{
"day": "Friday",
"time": "10:30PM "
},
{
"day": "Saturday",
"time": "10:30PM "
}]
},
{
"propCode": "foo6"
},
{
"propCode": "foo14",
"hours": [{
"day": "Sunday - Friday",
"time": "9:00AM - 5:00PM"
},
{
"day": "Saturday",
"time": "9:00AM - 6:00PM"
}]
},
{
"propCode": "foo14",
"hours": [{
"day": "Closed for ",
"time": "Winter Season"
}]
},
{
"propCode": "foo12",
"hours": [["CLOSED"]]
},
{
"propCode": "foo18",
"hours": [{
"day": "Box Office Tue-Sat",
"time": "12:00PM - 8:00PM"
}]
},
{
"propCode": "foo19"
},
{
"propCode": "foo20",
"hours": [{
"day": "Monday - Thursday",
"time": "<br>12:00PM - 3:00AM"
},
{
"day": "Friday - Sunday",
"time": "<br>10:00AM - 3:00AM"
},
{
"day": "Live Music",
"time": ", 6:00PM - 10:00PM"
}]
},
{
"propCode": "foo6",
"hours": [{
"day": "Sunday:",
"time": "5:00PM - 1:00AM "
},
{
"day": "Monday - Thursday:",
"time": "5:00PM - 1:00AM "
},
{
"day": "Friday:",
"time": "5:00PM - 2:00AM "
},
{
"day": "Saturday:",
"time": "5:00PM - 1:00AM "
}]
},
{
"propCode": "foo16",
"hours": [{
"day": "Daily",
"time": "24 Hours"
}]
},
{
"propCode": "foo21",
"hours": [{
"day": "Mon-Sat",
"time": "10:00AM - 2:00AM"
},
{
"day": "Sun",
"time": "12:00PM - 2:00AM"
}]
},
{
"propCode": "foo10"
},
{
"propCode": "foo23",
"hours": [{
"day": "Open Daily <br>(Seasonally)",
"time": "11:00AM - 6:00PM"
}]
},
{
"propCode": "foo22",
"hours": [{
"day": "Daily",
"time": "11:00AM - 3:00AM"
}]
},
{
"propCode": "foo23",
"hours": [
{
"day": "Sun - Thurs:",
"time": "9:00AM - 5:00PM"
},
{
"day": "Fri - Sat:",
"time": "9:00AM - 6:00PM"
},
{
"day": "Slide",
"time": "Closed for the season"
}
]
}
]
添加符号链接来解决。
我已经用homebrew安装了mysql并在输出中看到了这个。
mysql_config
取决于你如何Error: The `brew link` step did not complete successfully
它会在不同的地方。就我而言mysql
一旦你知道它在哪里,你就应该能够找到python正在寻找它的符号链接。 /usr/local/Cellar/mysql
这对我有用。
/usr/local/mysql
答案 20 :(得分:3)
您需要安装python-dev软件包:
sudo apt-get install python-dev
答案 21 :(得分:2)
sudo apt-get install python-mysqldb
Python 2.5?听起来你使用的是非常旧版本的Ubuntu Server(Hardy 8.04?) - 请确认服务器使用的是哪个Linux版本。
python-mysql search on ubuntu package database
其他一些信息:
来自mysql-python的自述文件 -
Red Hat 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更早的服务器分发版,那么您将失去官方支持,并且应该尽快升级。
答案 22 :(得分:2)
此方法仅适用于那些知道安装了Mysql但仍无法找到mysql_config的人。如果python install在您的系统路径中找不到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 installsudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py install
答案 23 :(得分:1)
只需输入:
$ sudo apt-get install python-dev
$ venv/bin/pip install MySQL-python
这将解决这个问题。
答案 24 :(得分:1)
到目前为止,所有解决方案(Linux)都需要sudo
或root权限才能安装。
如果您没有root权限并且没有sudo
,这是一个解决方案。 (否sudo apt install ...
):
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上测试。
答案 25 :(得分:1)
我有同样的问题。我通过遵循this tutorial在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
答案 26 :(得分:1)
实际错误是
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源的存档,并将头文件放在适当的文件夹中以便包含
答案 27 :(得分:1)
在CentOS 7中代替yum install mysql-devel
进行yum install mysql-community-devel
这不需要您添加mysql存储库。
答案 28 :(得分:1)
sudo apt-get build-dep python-mysqldb
将安装所有依赖项以从PIP / easy_install
答案 29 :(得分:1)
我遇到了同样的问题,只是添加了* mysql_config *所在的路径到环境变量PATH,它对我有用。
答案 30 :(得分:0)
对于macOS Mojave,需要附加配置,编译器才能找到 openssl ,您可能需要设置:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
答案 31 :(得分:0)
在CentOS 7中,应完成以下操作:
#step1:install mysql
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
#step2:
sudo yum install mysql-devel
答案 32 :(得分:0)
在MacOS(OS / X)Catalina上,我发现需要这样做:
export PATH=$PATH:/usr/local/bin/:/usr/local/mysql-5.7.16-osx10.11-x86_64/bin/
在我的计算机上,mysql
命令位于/usr/local/bin
中(来自标准MacOS安装程序,不是“ brew”)。
答案 33 :(得分:-2)
sudo apt-get install libmysqlclient-dev sudo apt-get install python-dev sudo apt-get install MySQL-python
你也应该安装python-dev,像MySQL-python这样的软件包是从源代码编译的。 pythonx.x-dev软件包包含用于链接python的必要头文件。 Why does installing numpy require python-dev in Kubuntu 12.04