关于mysql:EnvironmentError:找不到mysql_config

EnvironmentError: mysql_config not found

本问题已经有最佳答案,请猛点这里访问。

环境错误:安装mysql python时找不到mysql_config

有人能告诉我该怎么做吗?我从我这边做了以下事情:

安装PIP时出错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  [email protected]:~$ sudo pip install MySQL-python
    Downloading/unpacking MySQL-python
    Downloading MySQL-python-1.2.4.zip (113kB): 113kB downloaded
    Running setup.py egg_info for package MySQL-python
    sh: 1: mysql_config: not found
 Traceback (most recent call last):
  File"<string>", line 16, in <module>
  File"/tmp/pip_build_root/MySQL-python/setup.py", line 18, in <module>
    metadata, options = get_config()
  File"setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File"setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found

Traceback (most recent call last):

 File"<string>", line 16, in <module>

 File"/tmp/pip_build_root/MySQL-python/setup.py", line 18, in <module>

metadata, options = get_config()

File"setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File"setup_posix.py", line 25, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

  EnvironmentError: mysql_config not found

   ----------------------------------------
 Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_roo

我正在我的公司运行Ubuntu 12.04 LTS。

手动安装会产生相同的错误。我试过简单安装,也没用。

我手动搜索mysql_-config,在by-system文件中找不到它。

在快速搜索之后,我发现mysql_config属于libmysqlclient-dev。因此,我尝试使用以下方法获取这些包:

1
 sudo apt-get install libmysqlclient-dev

它提供以下输出:

1
2
3
4
5
6
7
8
9
10
  Reading package lists... Done
  Building dependency tree      
  Reading state information... Done
  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
  However the following packages replace it:
  mysql-server-5.5

  E: Package 'libmysqlclient-dev' has no installation candidate

我甚至从源代码下载了libmysqlclient-dev包,并尝试手动安装,这会导致依赖错误。以下是安装时的输出。

1
2
3
4
5
6
7
8
9
10
11
12
  ubuntu@ubuntu:~/Downloads$ sudo dpkg -i libmysqlclient-dev_5.5.32-            0ubuntu0.12.04.1_amd64.deb
  Selecting previously unselected package libmysqlclient-dev.
  (Reading database ... 203659 files and directories currently installed.)
   Unpacking libmysqlclient-dev (from libmysqlclient-dev_5.5.32-0ubuntu0.12.04.1_amd64.deb) ...
  dpkg: dependency problems prevent configuration of libmysqlclient-dev:
  libmysqlclient-dev depends on libmysqlclient18 (= 5.5.32-0ubuntu0.12.04.1); however:
  Version of libmysqlclient18 on system is 5.5.33+dfsg-1.
  dpkg: error processing libmysqlclient-dev (--install):
  dependency problems - leaving unconfigured
  Processing triggers for man-db ...
  Errors were encountered while processing:
  libmysqlclient-dev


总结其他SO问题中提供的一些解决方案(并基于错误输出)。首先,

1
sudo apt-get update

所以它的作用是

Used to re-synchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list(5).

并能解决

dpkg: dependency problems prevent configuration of libmysqlclient-dev

如果sudo apt-get install libmysqlclient-dev仍然不起作用,则随后运行以下命令

1
2
3
sudo apt-get install python-dev

sudo apt-get install python-mysqldb

最后,检查mysql_config是否在你的PATH中,必要时增加。

1
export PATH=$PATH:/path/to/your/mysql_config

可能解决

EnvironmentError: mysql_config not found

相似的:

  • https://askubuntu.com/questions/252777/how-can-i-resolve-dpkg-dependency
  • https://askubuntu.com/questions/222348/what-do-sudo-apt-get-update-do
  • https://askubuntu.com/questions/292865/upgrade-mysql-server-issue
  • pip install mysql python失败,环境错误:找不到mysql_config
  • virtualenv,mysql python,pip:有人知道怎么做吗?

尝试添加apt-get源列表,并使用apt-get进行安装,这样可以防止dpkg错误。

检查:https://www.howtoinstall.co/en/ubuntu/trusty/libmariadbclient-dev