如何解决这个Django / MySQL设置灾难?

时间:2012-11-13 08:15:28

标签: python mysql django macos mysql-python

我一直在搜索SO,论坛和博客帖子超过24小时。坦率地说,我完全不知道发生了什么。这似乎是一个复杂的问题,所以我会尽可能清楚地发布。

我正在使用Django,我正在尝试从sqlite切换到mysql。我按照这个SO答案中的说明进行操作:https://stackoverflow.com/a/3036241

当我运行最后一行python manage.py loaddata datadump.json时(或者当我尝试运行python manage.py syncdb时),我收到以下错误:

File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/commands/loaddata.py", line 13, in <module>
    from django.core import serializers
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/serializers/__init__.py", line 21, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/serializers/base.py", line 7, in <module>
    from django.db import models
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 24, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4-py2.7.egg/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

所以,我四处寻找如何解决这个问题,并尝试了这个:

pip install MySQL-python

一旦我跑了那条线,就会出现以下错误:

Downloading/unpacking MySQL-python
  Running setup.py egg_info for package MySQL-python
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gn/T/pip-build/MySQL-python/setup.py", line 18, 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: mysql_config: command not found

Traceback (most recent call last):

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

  File "/var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gn/T/pip-build/MySQL-python/setup.py", line 18, 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

尝试使用easy_install,只是为了确保。同样的错误。

所以,然后我尝试在setup_posix.py中修改mysql_config的路径,方法是按照以下步骤5和6 来回答:https://stackoverflow.com/a/1448476/1337422

当我转到该答案的第7步并运行sudo python setup.py build时,我收到以下错误:

running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.3-fat-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

为此,我找不到治愈方法。


顺便说一下,我也按照这个答案的说明:https://stackoverflow.com/a/1448446/1337422,然后跑了: sudo port install py26-mysql

这似乎没有任何修复。

(我在Mac OS 10.8.1上运行)


我迷失了,在这一点上毫无希望。我不知道还有什么地方可以帮助我们!

1 个答案:

答案 0 :(得分:1)

线索在这里:

unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

你需要安装编译器......我不是Mac用户,但是快速谷歌想出了http://www.tech-recipes.com/rx/726/mac-os-x-install-gcc-compiler/这可能有帮助

看起来像sudo port install gcc_select,然后sudo port install gcc<nnn>是关于正确的行......