码迷,mamicode.com
首页 > 数据库 > 详细

python安装mysqldb

时间:2015-12-14 19:15:15      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:python

python环境已经安装好,版本为2.7.8,需要调用数据库,所以需要安装MysqlDB模块包

下载地址:http://download.csdn.net/download/fhqsse220/5602861

安装过程:

  1. 解压及安装

    # tar -xf MySQL-python-1.2.3.tar.gz 

    #cd MySQL-python-1.2.3

    #python setup.py build

    #python setup.py install

2.错误解决

  导入模块报错:

  

/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /soft/MySQL-python-1.2.3 is being added to sys.path

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "MySQLdb/__init__.py", line 19, in <module>

    import _mysql

  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>

  File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__

ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory


创建动态库的链接:

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

&

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18


重新导入:

/usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg/_mysql.pyc, but /root/soft/MySQL-python-1.2.3 is being added to sys.path


离开当前目录,因为当前目录有相关模块

本文出自 “运维菜鸟” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1722899

python安装mysqldb

标签:python

原文地址:http://ckl893.blog.51cto.com/8827818/1722899

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!