gpt4 book ai didi

python - Django 中的 "No module name mysqldb"错误

转载 作者:搜寻专家 更新时间:2023-10-30 23:45:36 25 4
gpt4 key购买 nike

<分区>

我已经在带有 mysql 数据库引擎的 ubantu 14.04 上安装了 django 1.7(python 2.7.6),但是在运行命令时-

python manage.py migrate

我遇到了错误

(env1)shiv@shiv-Calpella:~/Project/Poll_app/mysite$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/base.py", line 297, in add_to_class
value.contribute_to_class(cls, name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 18, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

我试过通过命令安装mysqldb

pip install MySQL-python

然后我就报错了

    (env1)shiv@shiv-Calpella:~/Project/Poll_app/mysite$ pip install MySQL-pythonCollecting MySQL-python
Using cached MySQL-python-1.2.5.zip
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-3FRYWs/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found

Traceback (most recent call last):

File "<string>", line 20, in <module>

File "/tmp/pip-build-3FRYWs/MySQL-python/setup.py", line 17, in <module>

metadata, options = get_config()

File "setup_posix.py", line 43, in get_config

libs = mysql_config("libs_r")

File "setup_posix.py", line 25, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-3FRYWs/MySQL-python

我的setting.py文件是

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'poll_db',
'USER': 'root',
'PASSWORD': 'root',
}
}

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