重新安装 Mac OS 10.7 后 Django 开发环境损坏

Posted

技术标签:

【中文标题】重新安装 Mac OS 10.7 后 Django 开发环境损坏【英文标题】:Django Dev Environment Broken Following Mac OS 10.7 Reinstall 【发布时间】:2012-02-01 23:59:33 【问题描述】:

我最近遇到了我的硬盘驱动器问题,并使用 Disk Utilities 重新安装了 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

问题:

关于如何修复的任何提示? 关于我重新安装 Mac OS 10.7 时发生了什么变化/损坏的任何线索?

任何帮助表示赞赏。谢谢!

尝试构建/编译 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

【问题讨论】:

如果您可以编辑您的问题以包含您尝试安装 mysql-python 时遇到的错误,这将有所帮助。看到这个:***.com/questions/5671480/…. 谢谢@NathanJones。我在尝试安装 mysql-python 时添加了错误。 我花了几天时间解决这个问题,但没有解决。从内存中,我确实设法使用easy_install -U python-mysql 安装了mysql-python,但在尝试使用django 时仍然给我留下“找不到图像”错误。我知道有些人已经成功了,所以可以做到! 【参考方案1】:

你有两个选择:

    Manual Install 使用macports

要执行上述任一操作,您需要先安装 xcode - 可从 mac 应用商店下载(免费,但下载 4GB+)。

【讨论】:

谢谢@burhan。在升级到 Lion 之前,让它在没有 macports 的情况下工作。将审查手动安装步骤。

以上是关于重新安装 Mac OS 10.7 后 Django 开发环境损坏的主要内容,如果未能解决你的问题,请参考以下文章

VMware 装 Mac OS X 10.7 开启虚拟机后显示 EFI Network 求教

如何在 MAC OS X 10.7 Lion 上安装多个 XAMPP 版本或多个 PHP 版本

Qt Designer 4.8 在 Mac OS X 10.7 上启动时崩溃

适用于 MAC OS X 10.7 的 VLCKit

VirtualHosts 在 Mac OS 10.7 上不起作用

Mac OS X 10.7 (Lion) 中的 Nano 语法高亮显示?