我已经开始在我的Django开发中使用Pycharm,并遇到了这个错误。我知道我的MySQLdb正在工作,因为我可以在python shell中尝试导入它,并且我可以在命令行上运行syncdb命令。我的问题是,我需要向Pycharm添加什么才能使MySQLdb被识别。我正在makes上工作,如果这有什么不同的话。我是否需要向我的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发布于 2013-03-29 23:39:08
试一试
pip安装mysql-python
我认为在Pycharm中,您可以通过GUI安装这些包。但实际上,您需要安装mysql-python。
你可能需要执行sudo pip install mysql-python,如果你收到“权限被拒绝”的消息。
发布于 2013-03-30 14:32:25
PyCharm定义了用于每个项目的解释器,因此您需要仔细检查项目是否设置为使用以下任一选项:
如果您使用的不是virtualenv (您应该使用),请使用
发布于 2015-05-22 21:59:43
如果您使用的是python 3,mysql-python将不会安装,因为它不支持python 3。请使用mysqlclient。更多信息here。
https://stackoverflow.com/questions/15706383
复制相似问题