mysqldb构建错误

时间:2009-12-02 20:43:03

标签: python django macos osx-snow-leopard

我记得在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$ 

4 个答案:

答案 0 :(得分:1)

这是我个人的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)

它对我有用。我不能保证,但是......也许你会在里面找到一些有趣的提示。

请注意我使用的是自定义编译器(过时的原因太难以钻研)

答案 1 :(得分:1)

最可能的解释是,您尝试将64位版本的MySQL库与仅32位版本的Python链接(目前,OS X的所有python.org安装程序都是32位只要)。 (您可以对file中的库文件使用/usr/local/mysql/命令进行验证。

一些解决方案:

  • 使用Apple提供的python2.6 Snow Leopard是64位

  • 安装32位版本的MySQL库

  • 使用MacPortsinstall the base MacPorts infrastructure安装完整的解决方案,然后安装MySQLdb adapter for python 2.6(或2.5),它还将安装所有必需的依赖项,包括新的 python和MySQL客户端库应该都能正确地协同工作(并且可以 能够由MacPorts)更新:

    sudo port install py26-mysql # or py25-mysql

为了在MySQL上使用OS X和python,我推荐最后一个解决方案,即除非你真的喜欢并且有时间进行包管理和安装。从长远来看,它可能会为您省去很多麻烦。

P.S。 MacPorts还包括djangoPIL的端口:

sudo port install py26-django py26-pil

编辑:

要转到MacPorts路由,请按照我提供的说明here删除python.org安装程序python的效果。请勿尝试删除或修改/usr/bin/System/Library中Apple安装的Python文件;他们是OS X的一部分。然后按照上述说明安装MacPorts。为了避免干扰Apple或第三方安装,MacPorts将其所有文件安装到以/opt/local为根的完全独立的目录结构中。因此,您需要修改.bash_profile以将/opt/local/bin添加到$PATH。如果您希望首先找到MacPorts版本,请添加以下内容:

export PATH="/opt/local/bin:${PATH}"

当您开始新的终端会话时,您应该在MacPorts找到python2.6 python2.6。如果你还想让命令python指向那里:

$ sudo port install python_select
$ sudo python_select -l
Available versions:
current none python26 python26-apple
$ sudo python_select python26

答案 2 :(得分:0)

以下博客文章帮助我在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的最新版本。

答案 3 :(得分:0)

看起来您需要重新安装/更新XCode(构建工具)