python里安装mysql有错_Python安装Mysql驱动出错解决(最新出炉)

Python中最连接Mysql常用的驱动是

mysql-python :mysql的C语言的驱动

mysql-connector:msql官方的驱动

pymysql:python语言的驱动

我这里安装的是 mysql-python

终端中执行

pip install mysql-python

运气好的的话,直接就成功了,我遇到了一下问题,最终找到了解决方案,原因及解决方案如下,供参考

问题1:mysql_config not found

终端打印出:

Collecting mysql-python

Downloading MySQL-python-1.2.5.zip (108kB)

100% |████████████████████████████████| 110kB 30kB/s

Complete output from command python setup.py egg_info:

sh: mysql_config: command not found

Traceback (most recent call last):

File "", line 20, in

File "/private/tmp/pip-build-NP8J3v/mysql-python/setup.py", line 17, in

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

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-NP8J3v/mysql-python

解决方法,执行:

ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config

原因

找不到mysql_config一般是由于通过lnmp.org或者其他方式安装mysql以后mysql_config是在/usr/local/mysql/bin/里面,这里面的文件不是在任意位置都可以访问的,而指令是

将mysql_config链接到/usr/local/bin目录下

问题2:image not found python

出错信息为:

Traceback (most recent call last):

File "manage.py", line 4, in

from models import User

File "/Users/tengfei/PycharmProjects/mysql/models.py", line 1, in

import MySQLdb

File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in

import _mysql

ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib

Referenced from: /Library/Python/2.7/site-packages/_mysql.so

Reason: image not found

解决:

pip install --upgrade pip

修改 OS X 环境变量:打开终端,在终端中使用 vim 打开 “~/.bash_profile”,如果没有安装 vim,那就显示隐藏文件用文本编辑器打开,具体操作这里就不复述了。在 .bash_profile 中添加以下内容

PATH="/usr/local/mysql/bin:${PATH}"

export PATH

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

export VERSIONER_PYTHON_PREFER_64_BIT=no

export VERSIONER_PYTHON_PREFER_32_BIT=yes

其中 VERSIONER_PYTHON_PREFER_64_BIT 和 VERSIONER_PYTHON_PREFER_64_BIT 根据自己安装的 MySQL 进行选择。

参考:

问题3:command 'x86_64-linux-gnu-gcc' failed with exit status 1 异常解决

执行pip install mysql-python后的出错信息如下:

这是在虚拟环境中见到的

^

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/home/tengfei/api01/test/TestTo/TODO-orm/venv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-w6mp1W/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-jG7EKf-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/tengfei/api01/test/TestTo/TODO-orm/venv/include/site/python2.7/mysql-python" failed with error code 1 in /tmp/pip-build-w6mp1W/mysql-python/

原因是:一些依赖包没有安装,注意这也是很多实用pip执行安装扩展的时候,常见的错误

apt-get build-dep python-lxml

sudo pip install lxml --upgrade

pip install mysql-python

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值