2012-11-13 18 views
1

我一直在搜索SO,論壇和博客文章超過24小時。坦率地說,我完全不知道發生了什麼事。這似乎是一個複雜的問題,所以我會盡可能清楚地發佈。如何解決這個Django/MySQL安裝程序災難?

我正在使用Django,並試圖從sqlite切換到mysql。我跟着從這個指令,以便回答這樣做: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從該SO回答: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

的線索是在這裏:

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>大概是正確的...

+0

我不確定,但我認爲它已經安裝。當我運行'gcc -v'時,它返回'...線程模型:posix'' gcc version 4.2.1 ...'。 – sgarza62

+0

根據你的**編輯**,我用'sudo port install gcc_select'來安裝。當我運行'sudo port install gcc '時,它返回了這個錯誤:'-bash:意外標記附近的語法錯誤'newline''任何想法? – sgarza62

+0

@ sgarza62對不起 - ''應該是相關的版本號... –