Already installed Mysql-python, but in quoting the Times wrong: Importerror:no module named MySQLdb

Source: Internet
Author: User
Tags stdin

When importing the MySQLdb module, the error is as follows

>>> Import MySQLdb

Traceback (most recent):

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

Importerror:no module named MySQLdb


Found a solution on the Internet:

Yum Install Mysql-python (CentOS System)


Import again when the error, suspect is the version issue:

$ python--version

Python 2.7.10


$ cat/etc/issue

CentOS release 5.11 (Final)

Kernel \ r on an \m


This version of the system is installed by default with the python2.4 module:

$ RPM-QL Mysql-python

/usr/lib64/python2.4/site-packages/mysql_python-1.2.3c1-py2.4.egg-info

/usr/lib64/python2.4/site-packages/mysql_python-1.2.3c1-py2.4.egg-info/pkg-info

/usr/lib64/python2.4/site-packages/mysql_python-1.2.3c1-py2.4.egg-info/sources.txt

/usr/lib64/python2.4/site-packages/mysql_python-1.2.3c1-py2.4.egg-info/dependency_links.txt

/usr/lib64/python2.4/site-packages/mysql_python-1.2.3c1-py2.4.egg-info/top_level.txt

/usr/lib64/python2.4/site-packages/mysqldb

........

........


Workaround:

1, download mysql-python-1.2.5 on official website. Https://pypi.python.org/pypi/MySQL-python

2,unzip Mysql-python-1.2.5.zip

3, installation

CD mysql-python-1.2.5

Python setup.py Build

Python setup.py Install



Loading the module again is an error:

>>> Import MySQLdb

Traceback (most recent):

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

File "build/bdist.linux-x86_64/egg/mysqldb/__init__.py", line A, in <module>

File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, <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


According to the last hint, should be unable to find a libmysqlclient.so.18 file, so go to the MySQL installation directory to find this file and make a soft connection to the/usr/lib

ln-sv/usr/local/ver01/percona/lib/libmysqlclient.so.18/usr/lib64/libmysqlclient.so.18


No more error when loading the module again.


This article is from the "Always on the Road" blog, please be sure to keep this source http://chenql.blog.51cto.com/8732050/1760899

Already installed Mysql-python, but in quoting the Times wrong: Importerror:no module named MySQLdb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.