请帮助解决问题。我需要使用mysql for django。
我使用以下命令安装模块:
apt-get install python-mysqldb
接下来,我正在尝试创建一个表:
python ./manage.py syncdb
结果是以下错误消息:
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
刚试过:
pip install MySQL-python
easy_install MySQL-python
更多:
(mailsender_env)kalinin@kalinin ~/.virtualenvs/mailsender_project/mailsender $ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/build/MySQL-python/setup.py) egg_info for package MySQL-python
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/build/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 17, in <module>
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/build/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
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/kalinin/.virtualenvs/mailsender_project/mailsender_env/build/MySQL-python
Storing debug log for failure in /home/kalinin/.pip/pip.log
more:
(mailsender_env)kalinin@kalinin ~/.virtualenvs/mailsender_project/mailsender $ sudo apt-get install libmysqlclient-dev
Чтение списков пакетов… Готово
Построение дерева зависимостей
Чтение информации о состоянии… Готово
libmysqlclient-dev is already the newest version.
Следующие пакеты устанавливались автоматически и больше не требуются:
libgsoap4 liblcms2-2:i386 libvncserver0 ocl-icd-libopencl1:i386
Для их удаления используйте «apt-get autoremove».
обновлено 0, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 438 пакетов не обновлено.
(mailsender_env)kalinin@kalinin ~/.virtualenvs/mailsender_project/mailsender $ sudo apt-get install python-mysqldb
Чтение списков пакетов… Готово
Построение дерева зависимостей
Чтение информации о состоянии… Готово
python-mysqldb is already the newest version.
Следующие пакеты устанавливались автоматически и больше не требуются:
libgsoap4 liblcms2-2:i386 libvncserver0 ocl-icd-libopencl1:i386
Для их удаления используйте «apt-get autoremove».
обновлено 0, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 438 пакетов не обновлено.
(mailsender_env)kalinin@kalinin ~/.virtualenvs/mailsender_project/mailsender $ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/kalinin/.virtualenvs/mailsender_project/mailsender_env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
(mailsender_env)kalinin@kalinin ~/.virtualenvs/mailsender_project/mailsender $
答案 0 :(得分:1)
mysql_config
或安装程序找不到它。
# activate your virtualenv
# source virtualenv/bin/activate
sudo apt-get install libmysqlclient-dev
然后尝试以这种方式安装MySQLdb
:
sudo apt-get install python-mysqldb
您需要授予root权限才能安装python-mysqldb
。
须藤
使用超级用户(root)功能执行以下命令。 许多需要修改的行动
系统文件或安装应用程序需要额外的权限 经历。