ImportError: No module named 'MySQLdb'

来源:互联网 发布:二维码数据统计 编辑:程序博客网 时间:2024/05/22 16:51
  1. 在python3.4django 1.8环境中创建了一个project,在运行python manage.py runserver出现了如下问题:               ImportError: No module named 'MySQLdb'

[root@localhostmysite]# python manage.py runserver

Unhandledexception in thread started by <function check_errors.<locals>.wrapperat 0x7f9487d3ef28>

Traceback(most recent call last):

  File"/usr/local/lib/python3.4/site-packages/django/db/backends/mysql/base.py",line 24, in <module>

    import MySQLdb as Database

ImportError:No module named 'MySQLdb'

 

Duringhandling of the above exception, another exception occurred:

 

Traceback(most recent call last):

 

问题解决:需要安装pipinstall MySQL-python

 

来自 <https://segmentfault.com/q/1010000002539165>

 

但新的问题出现: ImportError: No module named 'ConfigParser'


[root@localhostmysite]# pip install MySQL-python

CollectingMySQL-python

  Using cached MySQL-python-1.2.5.zip

    Complete output from command pythonsetup.py egg_info:

    Traceback (most recent call last):

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

      File"/tmp/pip-build-xlcgim8c/MySQL-python/setup.py", line 13, in<module>

        from setup_posix import get_config

      File"/tmp/pip-build-xlcgim8c/MySQL-python/setup_posix.py", line 2, in<module>

        from ConfigParser importSafeConfigParser

    ImportError: No module named 'ConfigParser'

   

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

Command"python setup.py egg_info" failed with error code 1 in/tmp/pip-build-xlcgim8c/MySQL-python/

 

解决: 原来MySQL-python不支持python3,所以在python3环境下安装mysqlclient,问题最终解决

https://stackoverflow.com/questions/14087598/python-3-importerror-no-module-named-configparser

[root@localhostmysite]# pip install mysqlclient

原创粉丝点击