码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-09-30 12:55:08      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:lib   python   ldb   family   length   table   perl   att   core   

报错信息如下:

 File "D:\Project\megatech.ai\venv\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\models\base.py", line 124, in __new__
    new_class.add_to_class(‘_meta‘, Options(meta, app_label))
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
    value.contribute_to_class(cls, name)
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\utils.py", line 211, in __getitem__
    backend = load_backend(db[‘ENGINE‘])
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\utils.py", line 115, in load_backend
    return import_module(‘%s.base‘ % backend_name)
  File "C:\Python\Python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:\Project\megatech.ai\venv\lib\site-packages\django\db\backends\mysql\base.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)失败问题

标签:lib   python   ldb   family   length   table   perl   att   core   

原文地址:https://www.cnblogs.com/zhangtq/p/9728672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!