gpt4 book ai didi

python - 找不到 Pycharm Django Syncdb MySQLdb

转载 作者:行者123 更新时间:2023-11-30 23:20:31 26 4
gpt4 key购买 nike

我已经开始使用 Pycharm 进行 Django 开发,但遇到了这个错误。我知道我的 MySQLdb 正在工作,因为我可以在 python shell 中尝试导入它,并且可以在命令行上运行 syncdb 命令。我的问题是我需要向 Pycharm 添加什么才能识别 MySQLdb。如果这有什么不同的话,我正在使用 Mac OS X。我需要添加一些东西到我的 manage.py 还是需要添加到 Pycharm 的首选项?或者它是不同的东西。感谢您的帮助。

这是我遇到的错误:

    Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 21, in <module>
run_module(manage_file, None, '__main__', True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/Brandon/PycharmProjects/Database_assignment/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

Process finished with exit code 1

最佳答案

尝试

pip 安装 mysql-python

我认为在 Pycharm 中您可以通过 GUI 安装包。但本质上你需要安装mysql-python

如果收到“权限被拒绝消息”,您可能需要执行 sudo pip install mysql-python

关于python - 找不到 Pycharm Django Syncdb MySQLdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15706383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com