mysqldb构建错误
我记得在我的32位Mac上使用Leopard 10.5.7安装Python + Django + MySQL + MySQLdb。 我尝试了与Mac Snow Leopard相同的程序。但不幸的是遇到了很多错误... 我不知道,但一些奇怪的事情正在发生。请看错误日志:mysqldb构建错误
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$
下面的博客文章帮我编在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上的最新版本。
这对于
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 [email protected]
ALL_RUNTIME_TARGETS+=$(MYSQLDB_TARGET)
ALL_DOWNLOAD_TARGETS+=$(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
我个人的makefile规则和板块
$ 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)
而且它为我工作。我不能保证,但是......也许你会在里面找到一些有趣的提示。
请注意,我使用的是定制的编译器(过时的原因太丑陋钻研中)
嘿史蒂芬诺。恐怕这对我来说都是希腊人。我处于一个相当新生的阶段,上面的话只是吓到我。我在我以前的10.5.7 Mac上成功完成了这项工作。现在我拥有10.6的雪豹,生活就变成了地狱。我认为这与64位的事情有关。 – amit 2009-12-03 12:08:26
最有可能的解释是,你试图用一个链接MySQL的库的64位版本Python的32位版本(目前,OS X的所有python.org安装程序仅为32位)。 (您可以通过在/usr/local/mysql/
的库文件上使用file
命令来验证)。
一些解决方案:
使用上 雪豹其为64位
安装MySQL库的32位版本的
-
安装Apple提供
python2.6
使用MacPorts
的完整解决方案:install the base MacPorts infrastructure,然后安装MySQLdb adapter for python 2.6(或2.5),它也将安装所有nec埃森依赖关系,包括一个新的 Python和MySQL客户端库应该共同努力正确(并 能够通过MacPorts
更新):sudo port install py26-mysql # or py25-mysql
有关OS X
使用MySQL
与蟒蛇,我推荐最后的解决方案,也就是说,除非你真的喜欢并有时间去做包管理和安装。从长远来看,这可能会为您节省很多麻烦。
P.S.MacPorts的包括django
和PIL
端口,以及:
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}"
当你开始一个新的终端会话,你应该在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
我最初安装了32位版本的MySQL。它没有工作。然后我切换到64位的。在这个过程中,我已经从python 2.5.4切换到2.6.4以及其间的所有内容:)它真的让我和我的Mac很困惑。但我认为你在这里有一个观点。现在我想干净的重新安装。有没有办法删除安装在系统上的所有版本的python,然后重新安装? – amit 2009-12-03 12:06:02
看起来你需要重新安装/更新的XCode(编译工具)
请教关于Serverfault,姊妹网站到SO:HTTP:// serverfault.com/ – 2009-12-02 21:11:32
nope。这是一个编程问题。程序员比系统管理员更可能知道这些问题。 – 2009-12-03 02:53:18