简体   繁体   English

如何在Python中导入mysql模块?

[英]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 我正在尝试使用这个可重用的类来连接到MySQL与MySQL的Python连接

But whenever i try to run the python I am getting 但是每当我尝试运行python时,我都会

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... 我尝试安装MySQL-Python,结果显示在pip冻结上,表明已安装模块...

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? 谁能告诉我我在这里想念的东西吗?

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 我认为应该是import MySQLdb而不是仅仅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 如果您的类依赖于名为mysql模块,则无需更改类整个代码中的所有条目,也可以import MySQLdb as mysql

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM