我记得我在我的带有Leopard 10.5.7的32位Mac上安装了Python + Django + MySQL + MySQLdb。我在Mac Snow Leopard上尝试了同样的过程。但不幸的是遇到了很多错误...我不知道,但是发生了一些奇怪的事情。请查看错误日志:
Amit-Vermas-MacBook:mysql-python-1.2.2 amitverma$ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-i386-2.5/MySQLdb
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.3-i386-2.5
gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.3-i386-2.5/_mysql.o -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
from pymemcompat.h:10,
from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1050:1: warning: "HAVE_WCSCOLL" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:721:1: warning: this is the location of the previous definition
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1168:1: warning: "SIZEOF_LONG" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:811:1: warning: this is the location of the previous definition
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1177:1: warning: "SIZEOF_PTHREAD_T" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:820:1: warning: this is the location of the previous definition
error: command 'gcc-4.0' failed with exit status 1
Amit-Vermas-MacBook:mysql-python-1.2.2 amitverma$ 发布于 2009-12-03 10:51:52
这是我个人的makefile规则
MYSQLDB_VERSION=1.2.3c1
MYSQLDB_TARGET=$(BUILD_FLAGS_DIR)/mysqldb
MYSQLDB_PACKAGE=MySQL-python-$(MYSQLDB_VERSION).tar.gz
MYSQLDB_PACKAGE_URL=http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/$(MYSQLDB_VERSION)/$(MYSQLDB_PACKAGE)
.PHONY: mysqldb mysqldb-download
mysqldb: $(MYSQLDB_TARGET)
mysqldb-download: $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
$(MYSQLDB_TARGET): $(INIT_TARGET) $(MYSQLDB_DEPS) $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
-rm -rf $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION)
tar -m -C $(UNPACK_DIR) -xzvf $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
-cd $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION); \
for patch in $(PATCH_DIR)/mysqldb-$(MYSQLDB_VERSION)_$(ARCH)_*; \
do patch -p1 < $$patch; \
done
cd $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION); export CC="gcc -m64" FC="g95 -m64" CPPFLAGS="-I$(RUNTIME_DIR)/include" CFLAGS="-m64 -I$(RUNTIME_DIR)/include" LD_LIBRARY_PATH=$(RUNTIME_DIR)/lib64:$(RUNTIME_DIR)/lib:$$LD_LIBRARY_PATH PATH=$(RUNTIME_DIR)/bin:$$PATH PYTHONPATH=$(RUNTIME_DIR)/lib/python2.5/site-packages/; $(RUNTIME_DIR)/bin/python2.5 setup.py install --prefix=$(RUNTIME_DIR)
touch $(MYSQLDB_TARGET)
$(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE):
for package in $(MYSQLDB_PACKAGE_URL); \
do \
echo -n "Downloading $$package... "; \
cd $(DOWNLOAD_DIR); curl -L -O $$package; \
echo "done"; \
done
touch $@
ALL_RUNTIME_TARGETS+=$(MYSQLDB_TARGET)
ALL_DOWNLOAD_TARGETS+=$(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)还有一个补丁
$ more mysqldb-1.2.3c1_x86_64-apple-darwin10_patch-000
diff -Naur MySQL-python-1.2.3c1/setup.py MySQL-python-1.2.3c1.new/setup.py
--- MySQL-python-1.2.3c1/setup.py 2008-10-18 02:12:31.000000000 +0200
+++ MySQL-python-1.2.3c1.new/setup.py 2009-10-08 22:59:05.000000000 +0200
@@ -13,6 +13,8 @@
from setup_windows import get_config
metadata, options = get_config()
+options["extra_compile_args"].remove("-arch")
+options["extra_compile_args"].remove("x86_64")
metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
setup(**metadata)这对我来说很管用。我不能保证,但是...也许你会在里面找到一些有趣的提示。
请注意,我使用的是一个定制的编译器(出于过时的原因,太难看了,无法深入研究)
发布于 2009-12-03 11:57:07
最可能的解释是,您正在尝试将64位版本的MySQL库与仅32位版本的python.org链接(目前,OS X上的所有python.org仅为32位版本)。(您可以在/usr/local/mysql/中对库文件使用file命令来验证这一点)。
一些解决方案:
python2.6,它是64位的MacPorts是一个完整的解决方案,使用MacPorts:install the base MacPorts infrastructure,然后安装MySQLdb adapter for python 2.6 (或2.5),它还将安装所有必要的依赖项,包括新的python和MySQL客户端库,它们应该都可以正确地一起工作(并且能够通过<代码>D13进行更新):sudo port install py26-mysql # or py25-mysql
对于在OS X上使用MySQL和python,我推荐最后一个解决方案,也就是说,除非您真的喜欢并且有时间进行包管理和安装。从长远来看,这可能会为您省去很多麻烦。
P.S. MacPorts还包括django和PIL的端口:
sudo port install py26-django py26-pil编辑:
要使用MacPorts,请按照我给here的说明删除python.org安装程序python的影响。不要试图在/usr/bin或/System/Library中删除或修改苹果安装的Python文件;它们是OS X的一部分。然后按照上面引用的说明安装MacPorts。为了避免干扰苹果或第三方的安装,MacPorts将其所有文件安装到一个以/opt/local为根的完全独立的目录结构中。因此,您需要修改.bash_profile以将/opt/local/bin添加到$PATH中。如果您希望首先找到MacPorts版本,请添加类似以下内容:
export PATH="/opt/local/bin:${PATH}"当您开始一个新的终端会话时,您应该可以在python2.6上找到MacPorts python2.6。如果您还想让命令python指向该位置:
$ sudo port install python_select
$ sudo python_select -l
Available versions:
current none python26 python26-apple
$ sudo python_select python26发布于 2009-12-03 09:28:55
下面这篇博文帮助我在Mac上编译了MySQLdb 1.2.2:http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/
然而,后来我尝试了MySQLDB 1.2.3c1,没有遇到任何开箱即用的编译问题。1.2.2是几年前的版本,并在Python 2.6上引起弃用警告。我只需要切换到1.2.3.c1,看看它是否对您有效。
1.2.3c1是PyPi上的最新版本。
https://stackoverflow.com/questions/1835658
复制相似问题