无法在virtualenv上执行pip install mysql-python

时间:2013-09-16 05:58:27

标签: python mysql-python macports

我使用macports并且已经使用macports成功安装了mysql5,而我的python也由macports管理。目前我正在尝试在我的virtualenv上执行pip install mysql-python但是我收到一个错误,其中说找不到mysql_config:

    ~/code]$pip install mysql-python
    Downloading/unpacking mysql-python
      Running setup.py egg_info for package mysql-python
        sh: mysql_config: command not found
        Traceback (most recent call last):
          File "<string>", line 16, in <module>
          File "~/myVirtualEnv/build/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: mysql_config: command not found

    Traceback (most recent call last):

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

      File "~/myVirtualEnv/build/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

我阅读了很多谷歌的例子,但我阅读的更多内容帮助我进一步混淆了自己。

看起来macport遇到了问题但是它已经关闭了...... http://trac.macports.org/ticket/6982

4 个答案:

答案 0 :(得分:3)

MacPort在mysql_config5/opt/local/bin中创建符号链接/opt/local/lib/mysql5/bin/mysql_config。创建另一个名为mysql_config的链接。

cd /opt/local/bin
sudo ln -s /opt/local/lib/mysql5/bin/mysql_config .

我似乎还记得要创建一个my.cnf。默认情况下,Mac OSX使用所有默认值,但不创建my.cnf,创建一个/etc/my.cnf,它可能很简单。

我只是:

[mysqld]
bind-address = 0.0.0.0
port = 3306

答案 1 :(得分:1)

mysql_config是一个可执行文件,它位于libmysqlclient包中,因此您需要安装。在Deb系统上,你可以使用

安装它
sudo apt-get install libmysqlclient-dev
RPM中的

RPM equivalent: sudo yum install mysql-devel

在mac中可能

Macports - port install mysql5 +server

答案 2 :(得分:0)

将/ opt / local / lib / mysql5 / bin /添加到命令搜索路径,然后重新运行“pip install”命令应解决问题。

export PATH=/opt/local/lib/mysql55/bin/:$PATH
pip install mysql-python

答案 3 :(得分:0)

我遇到了同样的问题,并解决了该问题:

  1. 安装mysql。如果已安装,请忽略此步骤。
  2. yum install mysql-devel
    • 如果遇到类似Python.h: No such file or directory之类的错误,
      运行yum -y install python-devel