django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

前端 未结 23 1031
夕颜
夕颜 2020-12-02 10:51

The problem Im facing while trying to connect to database for mysql. I have also given the database settings that i have used.

 Traceback (most recent call l         


        
相关标签:
23条回答
  • 2020-12-02 11:19

    You are missing the python mysqldb library. Use this command (for Debian/Ubuntu) to install it: sudo apt-get install python-mysqldb

    0 讨论(0)
  • 2020-12-02 11:19

    On Ubuntu it is advised to use the distributions repository.

    sudo apt-get install python-mysqldb
    
    0 讨论(0)
  • 2020-12-02 11:19

    I was having the same problem.The following solved my issue

    Run pip install pymysql in your shell

    Then, edit the init.py file in your project origin directory(the same as settings.py) and then

    add:

    import pymysql

    pymysql.install_as_MySQLdb()

    this should solve the problem.

    0 讨论(0)
  • 2020-12-02 11:20

    This happened with me as well and I believe this has become a common error not only for Django developers but also for Flask as well, so the way I solved this issue was using brew.

    1. brew install mysql
    2. sudo pip install mysql-python

    This way every single issue was solved and both frameworks work absolutely fine.

    P.S.: For those who use macports (such as myself), this can be an issue as brew works in a different level, my advice is to use brew instead of macports

    I hope I could be helpful.

    0 讨论(0)
  • 2020-12-02 11:20

    Faced similar issue. I tried installing mysql-python using pip, but it failed due to gcc dependency errors.

    The solution that worked for me

    conda install mysql-python
    

    Please note that I already had anaconda installed, which didn't had gcc dependency.

    0 讨论(0)
  • 2020-12-02 11:24

    It looks like you don't have the python mysql package installed, try:

    pip install mysql-python
    

    or if not using a virtual environment (on *nix hosts):

    sudo pip install mysql-python
    
    0 讨论(0)
提交回复
热议问题