我试图让一个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?


当前回答

下面是我在Ubuntu 12.04 LTS上使用的:

apt-get install libmysqlclient-dev python-dev

尽管它很有效,但我还是继续做了下面的事情:

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

其他回答

类型:

$ sudo apt-get install python-dev
$ venv/bin/pip install MySQL-python

这将解决这个问题。

我也有同样的问题。我通过遵循本教程在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

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

(如果您使用的是python3,请改为安装python3-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...

到目前为止,所有解决方案(Linux)都需要sudo或root权限才能安装。 这里有一个解决方案,如果你没有根权限,没有sudo。(no sudo apt install…)

下载libmysqlclient-dev的.deb文件,例如从这个镜像 导航到下载的文件并运行dpkg -x libmysqlclient-dev_<version tag>.deb。这将提取一个名为usr的文件夹。 Symlink ./usr/bin/mysql_config到你的$PATH: ln -s ' pwd ' /usr/bin/mysql_config FOLDER_IN_YOUR_PATH 它现在应该能够找到mysql_config

在Ubuntu 18.04上测试。

实际误差是

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源文件,并将头文件放在适当的文件夹中进行包含