请问老师创建时进入python console 时提示,然后无法按照步骤创建用户信息

来源:3-2 使用ORM实现新增操作

慕粉232102761

2020-02-02 17:34:36

F:\Python\python.exe "D:\pycharm\PyCharm 2019.3.1\plugins\python\helpers\pydev\pydevconsole.py" --mode=client --port=52603

import sys; print('Python %s on %s' % (sys.version, sys.platform))

import django; print('Django %s' % django.get_version())

sys.path.extend(['H:\\py_learn\\test_django', 'D:\\pycharm\\PyCharm 2019.3.1\\plugins\\python\\helpers\\pycharm', 'D:\\pycharm\\PyCharm 2019.3.1\\plugins\\python\\helpers\\pydev'])

if 'setup' in dir(django): django.setup()

import django_manage_shell; django_manage_shell.run("H:/py_learn/test_django")

PyDev console: starting.

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32

Django 1.11.18

Traceback (most recent call last):

  File "F:\Python\lib\site-packages\django\db\backends\mysql\base.py", line 26, in <module>

    import MySQLdb as Database

  File "D:\pycharm\PyCharm 2019.3.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import

    module = self._system_import(name, *args, **kwargs)

ModuleNotFoundError: No module named 'MySQLdb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<input>", line 6, in <module>

  File "F:\Python\lib\site-packages\django\__init__.py", line 27, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "F:\Python\lib\site-packages\django\apps\registry.py", line 108, in populate

    app_config.import_models()

  File "F:\Python\lib\site-packages\django\apps\config.py", line 202, in import_models

    self.models_module = import_module(models_module_name)

  File "F:\Python\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import

  File "<frozen importlib._bootstrap>", line 983, in _find_and_load

  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 728, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "F:\Python\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>

    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

  File "D:\pycharm\PyCharm 2019.3.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import

    module = self._system_import(name, *args, **kwargs)

  File "F:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>

    class AbstractBaseUser(models.Model):

  File "F:\Python\lib\site-packages\django\db\models\base.py", line 124, in __new__

    new_class.add_to_class('_meta', Options(meta, app_label))

  File "F:\Python\lib\site-packages\django\db\models\base.py", line 325, in add_to_class

    value.contribute_to_class(cls, name)

  File "F:\Python\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 "F:\Python\lib\site-packages\django\db\__init__.py", line 33, in __getattr__

    return getattr(connections[DEFAULT_DB_ALIAS], item)

  File "F:\Python\lib\site-packages\django\db\utils.py", line 211, in __getitem__

    backend = load_backend(db['ENGINE'])

  File "F:\Python\lib\site-packages\django\db\utils.py", line 115, in load_backend

    return import_module('%s.base' % backend_name)

  File "F:\Python\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "F:\Python\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?


写回答

2回答

好帮手乔木

2020-02-02

同学你好:

这是由于同学的python环境中缺少mysqlclient这个包。

pip install mysqlclient

或者

下载 mysqlclient-1.3.7-cp27-none-win_amd64.whl

链接:https://files-cdn.cnblogs.com/files/followyourheart/mysqlclient-1.3.7-cp27-none-win_amd64.zip

打开命令行,切换到下载的文件所在目录然后安装:

pip install mysqlclient-1.3.7-cp27-none-win_amd64.whl

如果我解决了同学的问题,请采纳!学习愉快^_^。


0

慕粉232102761

提问者

2020-02-02

通过Terminal控制台能够创建成功!

什么问题?

0

0 学习 · 3562 问题

查看课程