• Django 错误之 No module named ‘MySQLdb’



    报错如下:
    File "/usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 27, in <module>

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


    MySQLdb 只适用于python2.x,。在python3.x的替代品是: import pymysql

    解决办法:

    base.py 文件同目录下的__init__.py文件新增如下两行:

    vi /usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/__init__.py

    import pymysql
    pymysql.install_as_MySQLdb()

    如果还报如下错误:
    AttributeError: module 'pymysql' has no attribute 'install_as_MySQLdb'

    解决方法:
    pip uninstall PyMySQL3
    pip install -U --force-reinstall pymysql

  • 相关阅读:
    JS异错面试题
    CSG
    OBS工具汇总
    SFS OBS
    zookeeper配置文件
    zookeeper概念
    centos yum源问题三板斧
    nexus仓库
    SVN备份恢复
    ubuntu
  • 原文地址:https://www.cnblogs.com/liang545621/p/10233857.html
Copyright © 2020-2023  润新知