Python2安装数据库驱动(Mysql_Python)失败问题

Posted 是张不是章啊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python2安装数据库驱动(Mysql_Python)失败问题相关的知识,希望对你有一定的参考价值。

报错信息如下:

 File "D:Projectmegatech.aivenvlibsite-packagesdjangocontribauthmodels.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "D:Projectmegatech.aivenvlibsite-packagesdjangocontribauthase_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbmodelsase.py", line 124, in __new__
    new_class.add_to_class(‘_meta‘, Options(meta, app_label))
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbmodelsase.py", line 325, in add_to_class
    value.contribute_to_class(cls, name)
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbmodelsoptions.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodb\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbutils.py", line 211, in __getitem__
    backend = load_backend(db[‘ENGINE‘])
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbutils.py", line 115, in load_backend
    return import_module(‘%s.base‘ % backend_name)
  File "C:PythonPython27Libimportlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:Projectmegatech.aivenvlibsite-packagesdjangodbackendsmysqlase.py", line 30, in <module>
    ‘Did you install mysqlclient or MySQL-python?‘ % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb.
Did you install mysqlclient or MySQL-python?

 

 

 

 解决方案:

1.安装pymysql的包

2.在项目的init文件中添加如下代码

# import pymysql
# pymysql.install_as_MySQLdb()

 



以上是关于Python2安装数据库驱动(Mysql_Python)失败问题的主要内容,如果未能解决你的问题,请参考以下文章

如何在CentOS6上安装Python2.7和Python3.3

使用python2连接操作db2

数据驱动python之mysql的操作

如何在CentOS6上安装Python2.7和Python3.3

python专题-Mysql数据库(python3._+ PyMysql)

caffe的python接口求助