命令" python setup.py egg_info" / tmp / pip-install-fs0wmmw4 / mysqlclient /中的错误代码1失败

时间:2018-04-16 16:53:50

标签: python mysql ubuntu-16.04

在Ubuntu 16.04中输入以下命令时

$ pip install mysqlclient

我收到以下错误:

`enter code here`Collecting mysqlclient
  Downloading https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz (89kB)
    100% |████████████████████████████████| 92kB 136kB/s 
    Complete output from command python setup.py egg_info:
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-fs0wmmw4/mysqlclient/

3 个答案:

答案 0 :(得分:10)

请尝试以下说明:

https://github.com/PyMySQL/mysqlclient-python

或者如果你正在使用python 3.使用这些命令:

sudo apt-get install libmysqlclient-dev

sudo pip3 install mysqlclient

他们都在我的案件中工作。

希望!!这有帮助

答案 1 :(得分:4)

我刚刚在 Debian 10 上遇到了这个问题:

根据github(https://github.com/PyMySQL/mysqlclient)现在应该使用这个:

如果您使用的是 # Debian / Ubuntu,请先运行:

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

如果您使用的是 # Red Hat / CentOS 首次运行:

sudo yum install python3-devel mysql-devel

然后就可以安装mysqlclient了:

pip install mysqlclient

答案 2 :(得分:1)

经过一些调查并尝试了不同的解决方案,我发现了以下几点:

1-大多数用户在Ubuntu 16.04上从apt-get安装Python。

2-主Ubuntu存储库中存在的版本为3.5.x。与mysqlclient一起安装的pip对于版本低于v3.6的python3出现问题。因此,您应该安装Python3.6。

3-如果您使用的是Windows,则可以将mysqlclient的编译版本用作wheel文件。您可以找到一些滚轮文件here。只需下载文件,然后:

pip install "path-of-wheel-file"

4-如果您按照here的说明使用Ubuntu,请通过以下命令安装python3.6:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6 python3.6-dev libmysqlclient-dev libmysqld-dev unzip

5-您应该更新setuptools

python -m pip install --upgrade pip setuptools wheel

对于python3.6:

python3.6 -m pip install --upgrade pip setuptools wheel

6-在最后一步,您应该从源代码安装mysqlclient:

wget https://github.com/PyMySQL/mysqlclient-python/archive/master.zip
unzip master.zip
cd mysqlclient-python-master
python setup.py install

如果您使用的是Django 1.11 LTS版本,则应克隆一个较旧的mysqlclient版本(例如:v1.3.13):

wget https://github.com/PyMySQL/mysqlclient-python/archive/1.3.13.zip
unzip 1.3.13.zip
cd mysqlclient-python-master
python setup.py install