我最近遇到了硬盘问题,并使用磁盘工具重新安装Mac OS 10.7 Lion 当我去运行我的Django应用程序时,我遇到了以下错误:
################ BEGIN ERRORS ##################
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_manager(settings)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/helpers.py", line 3, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/utils.py", line 33, in load_backend
return import_module('.base', backend_name)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
################ END ERRORS ##################
关于我的设备环境的信息:
我的本地开发环境使用virtualenv和virtualenvwrapper。
我在我的虚拟环境中检查了中的以下内容(即运行这些命令后:workon my_project; cdvirtualenv
):
% which python: /Users/my_username/Sites/python_projects/my_project/bin/python
>>> import sys
>>> sys.version
'2.7.1 (r271:86832, Jul 31 2011, 19:30:53) \n[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]'
% which mysql: /usr/local/mysql/bin/mysql
>>> import django
>>> django.VERSION
(1, 3, 0, 'final', 0)
我将注意力集中在使用Internet上的各种配方(例如http://birdhouse.org/blog/2009/09/27/python-mysql-connections-and-snow-leopard/)重新安装mysql-python
连接器。没运气。所有重新安装mysql-python的尝试都失败了很多错误。不知道为什么我还需要重新安装mysql-python。
echo $PATH
-----------
/Users/my_username/Sites/python_projects/my_project/bin:/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Developer/usr/bin
echo $PYTHONPATH
-----------------
/Users/my_username/lib/python
问题:
任何帮助表示赞赏。谢谢!
在尝试构建/编译mysql-python时附加错误消息:
% pwd
/Users/my_username/MySQL-python-1.2.3b2
% ARCHFLAGS='-arch x86_64' python setup.py build
--------------------------------------------------
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.7-x86_64-2.7/MySQLdb
running build_ext
building '_mysql' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'beta',2) -D__version__=1.2.3b2 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.7-x86_64-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch i386
In file included from _mysql.c:29:
pymemcompat.h:10:20: error: Python.h: No such file or directory
_mysql.c:30:26: error: structmember.h: No such file or directory
In file included from _mysql.c:37:
/usr/local/mysql/include/mysql.h:47:23: error: sys/types.h: No such file or directory
In file included from /usr/local/mysql/include/mysql.h:72,
from _mysql.c:37:
/usr/local/mysql/include/mysql_com.h:455: error: expected declaration specifiers or '...' before 'size_t'
/usr/local/mysql/include/mysql_com.h:457: error: expected declaration specifiers or '...' before 'size_t'
/usr/local/mysql/include/mysql_com.h:459: error: expected declaration specifiers or '...' before 'size_t'
/usr/local/mysql/include/mysql_com.h:460: error: expected declaration specifiers or '...' before 'size_t'
/usr/local/mysql/include/mysql_com.h:461: error: expected declaration specifiers or '...' before 'size_t'
In file included from /usr/local/mysql/include/typelib.h:20,
from /usr/local/mysql/include/mysql.h:131,
from _mysql.c:37:
/usr/local/mysql/include/my_alloc.h:44: error: expected specifier-qualifier-list before 'size_t'
_mysql.c:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
_mysql.c:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
_mysql.c:63: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
[ OMITTED QUITE A NUMBER OF LINES TO PROTECT THE INNOCENT ]
_mysql.c:2533: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_ConnectionObject_Type'
_mysql.c:2617: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_ResultObject_Type'
_mysql.c:2703: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_methods'
_mysql.c:2775: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
_mysql.c:2807: warning: return type defaults to 'int'
_mysql.c: In function 'DL_EXPORT':
_mysql.c:2807: error: expected declaration specifiers before 'init_mysql'
_mysql.c:2885: error: expected '{' at end of input
error: command 'llvm-gcc-4.2' failed with exit status 1
答案 0 :(得分:0)
您有两种选择:
要执行其中任何一项,您需要先安装xcode - 可从mac应用商店购买(免费,但4GB +下载)。