Error installing pymssql on Mac OS X Lion

匿名 (未验证) 提交于 2019-12-03 02:53:02

问题:

I have XCode installed and also FreeTDS. I tried to connect to my SQL Server and it works perfect.

==> 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 

Any help or clue?

回答1:

Unfortunately, pymssql's setup.py (as of version pymssql-2.0.0b1-dev-20111019) needs a bit of help to work properly on OSX Lion. The current setup.py tries to compile/link against some pre-built Linux FreeTDS libraries, and also tries to link against librt, which doesn't exist on OSX. Additionally, it only explicitly looks for FreeTDS libraries from Fink or MacPorts, so if you've installed Homebrew (if you use if) or FreeTDS itself in a non-standard location, it may not be located by compiler/linker.

I created a repaired version of setup.py here. It worked well enough for me with the Homebrew build of FreeTDS using the standard locations (/usr/local/{lib, include}), but as always YMMV. You may need to adjust setup.py further if you've installed FreeTDS in a different location. You can generally ignore the warnings from the linker about missing directories that may not exist on your system:

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

One other note: You will probably have built FreeTDS for a single architecture, likely x86_64. By default, pymssl will be a multi-architecture build (assuming you're using the system Python 2.7.1), so even with a patched setup.py you will see a linker warning something like:

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

That warning just indicates that the FreeTDS libraries only have single architecture version to link against. You can avoid the warning by using ARCHFLAGS to make a x86_64-only build:

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



回答2:

Or, try this fork, it installs without issues:

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

To install on OS X Mavericks, you need

OS X Command Line Tools

FreeTDS

brew install freetds 

Cython

pip install cython 

and then finally you can install the pymssql-macoslion

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


回答3:

Just incase anyone is reading this the following worked for me:

brew install freetds sudo pip install pymssql 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!