it-swarm.cn

安装MySQL-python

我试图在我的Ubuntu/Linux Box上安装MySQL-python时遇到了以下故障。从下面看来问题是sh: mysql_config: not found有人可以建议我做什么吗?

[email protected]:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py Egg_info for package MySQL-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/rmicro/build/MySQL-python/setup.py", line 15, 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 24, 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: not found

Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/home/rmicro/build/MySQL-python/setup.py", line 15, 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 24, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py Egg_info failed with error code 1
62
user618677

在Ubuntu上,建议使用分发存储库。所以安装python-mysqldb应该是直截了当的:

Sudo apt-get install python-mysqldb

如果你真的想使用pip进行安装,这是前面提到的不是建议的路径但可能,请看一下之前提出的问题和答案: pip install mysql-python失败,出现EnvironmentError:找不到mysql_config

这是开发人员非常全面的指南: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html

要获得python-mysqld使用pip安装它的所有先决条件(如果您使用的是virtualenv,则需要执行此操作),运行以下命令:

Sudo apt-get install build-essential python-dev libmysqlclient-dev
153
Glaslos

您有2个选项,如下所述:


像Glaslos这样的分发包建议:

# Sudo apt-get install python-mysqldb

在这种情况下,您不能使用virtualenv no-site-packages(默认选项),但必须使用:

# virtualenv --system-site-packages myenv

使用clean virtualenv并构建自己的python-mysql包。

首先创建virtualenv:

# virtualenv myvirtualenv
# source myvirtualenv/bin/activate

然后安装构建依赖项:

# Sudo apt-get build-dep python-mysqldb

现在你可以安装python-mysql了

# pip install mysql-python

_ note _ Ubuntu包是python-mysql * db *,python pypi包是python-mysql(没有 db

14
Luka Marinko
yum install mysql-devel

它对我有用。

9
Mayank

重新读取错误消息。它说:

sh:mysql_config:找不到

如果你在Ubuntu Natty上,mysql_config属于包 libmysqlclient-dev

7
gsbabil

这对我在python 3上工作

pip install mysqlclient

2
Jouhayna
  1. 找到文件夹:Sudo find / -name "mysql_config"(假设它是"/opt/local/lib/mysql5/bin"

  2. 将其添加到PATH中:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH

  3. 再次安装

1
xiecheng127

使用MySQL的Python或Python3,您将需要这些。这些库使用MySQL的C和Python连接器(您还需要安装C库),它克服了mysqldb库的一些限制。

   Sudo apt-get install libmysqlclient-dev
   Sudo apt-get install python-mysql.connector
   Sudo apt-get install python3-mysql.connector
1
David Peterson Harvey