hutanrimba
hutanrimba

Reputation: 149

How to import mysql modules in Python?

As you are aware, I am a complete noob on this.

I am trying to use this reusable class to connect to mysql Python Connection with MySQL

But whenever i try to run the python I am getting

Traceback (most recent call last):
 File "src/connect.py", line 1, in <module>
    from Mysql import Mysql
  File "/home/ubuntu/myproject/src/Mysql.py", line 1, in <module>
    import mysql
ImportError: No module named mysql

I tried installing MySQL-Python, and result shown on pip freeze says that the modules installed...

easy_install MySQL-python
Searching for MySQL-python
Best match: MySQL-python 1.2.5
Adding MySQL-python 1.2.5 to easy-install.pth file

Using /home/ubuntu/myproject/lib/python2.7/site-packages
Processing dependencies for MySQL-python
Finished processing dependencies for MySQL-python
pip freeze
    Cheetah==2.4.4
    Landscape-Client==14.01
    MySQL-python==1.2.3
    PAM==0.4.2
    PyYAML==3.10
    Twisted-Core==13.2.0
    Twisted-Names==13.2.0
    Twisted-Web==13.2.0
    apt-xapian-index==0.45
    argparse==1.2.1
    chardet==2.0.1
    cloud-init==0.7.5
    configobj==4.7.2
    jsonpatch==1.3
    jsonpointer==1.0
    oauth==1.0.1
    prettytable==0.7.2
    pyOpenSSL==0.13
    pycurl==7.19.3
    pyserial==2.6
    python-apt==0.9.3.5
    python-debian==0.1.21-nmu2ubuntu2
    requests==2.2.1
    six==1.5.2
    ssh-import-id==3.21
    urllib3==1.7.1
    virtualenv==1.11.6
    wsgiref==0.1.2
    zope.interface==4.0.5

Can anyone tell me what I am missing here?

Upvotes: 0

Views: 734

Answers (1)

surajravi
surajravi

Reputation: 313

Can you provide details on that reusable class, (maybe post the file via paste bin and then provide a link to it or something).

I think it should be import MySQLdb rather than just import mysql

If your class relies on this module being named as mysql then instead of changing all the entries in the entire code of the class you could also just do import MySQLdb as mysql

Hope this helps.

Upvotes: 2

Related Questions