在Mac OS X Lion上安装pymssql时出错

时间:2012-02-06 14:37:55

标签: python pymssql

我安装了XCode,还安装了FreeTDS。我试图连接到我的SQL Server,它完美无缺。

现在我必须在python上开发一个与这个SQL Server一起使用的应用程序,我正在尝试安装pymsql,但是当我启动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

任何帮助或线索?

3 个答案:

答案 0 :(得分:11)

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

我创建了一个已修复版本的setup.py here。使用标准位置(/ usr / local / {lib,include}),FreebDS的Homebrew构建对我来说效果很好,但总是YMMV。如果您在其他位置安装了FreeTDS,则可能需要进一步调整setup.py.您通常可以忽略链接器中有关系统上可能不存在的缺少目录的警告:

ld:警告:找不到选项'-L / usr / local / lib / freetds'的目录

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

ld:警告:忽略文件/usr/local/lib/libsybdb.dylib,文件是为不支持的文件格式构建的,而不是所链接的体系结构(i386)

该警告仅表示FreeTDS库仅具有要链接的单一体系结构版本。您可以使用ARCHFLAGS来制作仅限x86_64的版本来避免警告:

ARCHFLAGS =“ - arch x86_64”python setup.py install

答案 1 :(得分:4)

或者,试试这个fork,它安装没有问题:

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 :(得分:2)

只是因为有人正在读这个以下为我工作:

brew install freetds
sudo pip install pymssql