我一直在搜索 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试了一下,只是为了确保。同样的错误。
因此,然后我尝试按照此 SO 答案中的步骤 5 和 6更改 setup_posix.py 中 mysql_config 的路径: 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 上运行)
在这一点上,我很迷茫,也很绝望。我不知道还能去哪里……帮帮我!