在Mac OS X Lion上安装pymssql出错

3
我已经安装了XCode和FreeTDS。我尝试连接到我的SQL Server,它完美地工作。
现在我需要开发一个Python应用程序来与这个SQL Server一起工作,我正在尝试安装pymysql,但是当我运行sudo python setup.py命令时出现了以下错误:
==> sudo python setup.py install
running install
running bdist_egg
running egg_info
writing pymssql.egg-info/PKG-INFO
writing top-level names to pymssql.egg-info/top_level.txt
writing dependency_links to pymssql.egg-info/dependency_links.txt
reading manifest file 'pymssql.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pymssql.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-intel/egg
running install_lib
running build_ext
skipping '_mssql.c' Cython extension (up-to-date)
building '_mssql' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/sw/include -Ifreetds/nix_64/include -I/opt/local/include -I/opt/local/include/freetds -I/opt/local/freetds/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mssql.c -o build/temp.macosx-10.7-intel-2.7/_mssql.o -DMSDBLIB
_mssql.c: In function ‘__pyx_f_6_mssql_15MSSQLConnection_convert_python_value’:
_mssql.c:7322: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c: In function ‘__pyx_f_6_mssql_15MSSQLConnection_get_result’:
_mssql.c:9554: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c:9566: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c: In function ‘__pyx_pf_6_mssql_20MSSQLStoredProcedure_2bind’:
_mssql.c:11146: warning: implicit conversion shortens 64-bit value into a 32-bit value
llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/_mssql.o -L/sw/lib -Lfreetds/nix_64/lib -L/opt/local/lib -L/opt/local/lib/freetds -L/opt/local/freetds/lib -lsybdb -lrt -o build/lib.macosx-10.7-intel-2.7/_mssql.so
ld: warning: directory not found for option '-L/sw/lib'
ld: warning: directory not found for option '-L/opt/local/lib'
ld: warning: directory not found for option '-L/opt/local/lib/freetds'
ld: warning: directory not found for option '-L/opt/local/freetds/lib'
ld: library not found for -lrt
collect2: ld returned 1 exit status
ld: warning: directory not found for option '-L/sw/lib'
ld: warning: directory not found for option '-L/opt/local/lib'
ld: warning: directory not found for option '-L/opt/local/lib/freetds'
ld: warning: directory not found for option '-L/opt/local/freetds/lib'
ld: library not found for -lrt
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//cc6eQsIN.out (No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1

有什么需要帮助或线索吗?


你创建了文件夹:"/sw/lib","/opt/local/lib"吗? - CarlJ
3个回答

11

很不幸,pymssql的setup.py在OSX Lion上无法正常工作(截至pymssql-2.0.0b1-dev-20111019版本)。当前的setup.py试图编译链接一些预编译的Linux FreeTDS库,并尝试链接librt,但在OSX上不存在。此外,它只显式查找来自Fink或MacPorts的FreeTDS库,因此如果您在非标准位置安装了Homebrew(如果使用)或FreeTDS本身,则编译器/链接器可能无法找到它。

我创建了一个修复过的setup.py版本,在这里。使用/usr/local/{lib,include}的标准位置和Homebrew版本的FreeTDS足够好地运行,但始终因人而异。如果您已在不同位置安装了FreeTDS,则可能需要进一步调整setup.py。您通常可以忽略链接器有关可能不存在于系统上的目录的警告:

ld: warning: directory not found for option '-L/usr/local/lib/freetds'

另外请注意:您可能已经为单个架构(可能是x86_64)构建了FreeTDS。默认情况下,pymssl将是多架构构建(假设您正在使用系统Python 2.7.1),因此即使使用了修补的setup.py,您仍将看到类似以下的链接器警告:

ld: warning: ignoring file /usr/local/lib/libsybdb.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

该警告只是表示FreeTDS库只有单个架构版本可供链接。您可以使用ARCHFLAGS制作x86_64-only的构建以避免此警告:

ARCHFLAGS="-arch x86_64" python setup.py install


+1 很好的解释并且提供了setup.py的链接有助于正确地使事情工作。 - dlamotte

4

或者,尝试这个分支,它可以无问题地安装:

https://github.com/blackbass1988/pymssql-macos-lion

要在OS X Mavericks上安装,您需要:

OS X命令行工具

FreeTDS

brew install freetds

Cython
pip install cython

最后,您可以安装 pymssql-macoslion。

pip install git+git://github.com/blackbass1988/pymssql-macos-lion.git@master

2

如果有人在阅读这篇文章,以下内容适用于我:

brew install freetds
sudo pip install pymssql

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接