我使用Mac(OS X 10.11.5)。我想为python安装模块pymssql
。
在Terminal.app
,我输入了sudo -H pip install pymssql
,pip install pymssql
,sudo pip install pymssql
。但是错误发生了。
目录
/Users/janghyunsoo/Library/Caches/pip/http
或其父目录不属于当前用户,并且已禁用缓存。请检查该目录的权限和所有者。如果使用pip
执行sudo
,您可能需要sudo
-H
标记。目录
/Users/janghyunsoo/Library/Caches/pip
或其父目录不属于当前用户,并且已禁用缓存轮。检查该目录的权限和所有者。如果使用pip
执行sudo
,您可能需要sudo
-H
标记。
Collecting pymssql
Downloading pymssql-2.1.2.tar.gz (898kB)
100% |████████████████████████████████| 901kB 955kB/s
Installing collected packages: pymssql
Running setup.py install for pymssql ... error
Complete output from command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-KA5ksi/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-A3wRBy-record/install-record.txt --single-version-externally-managed --compile:
setup.py: platform.system() => 'Darwin'
setup.py: platform.architecture() => ('64bit', '')
setup.py: platform.libc_ver() => ('', '')
setup.py: Detected Darwin/Mac OS X.
You can install FreeTDS with Homebrew or MacPorts, or by downloading
and compiling it yourself.
Homebrew (http://brew.sh/)
--------------------------
brew install freetds
MacPorts (http://www.macports.org/)
-----------------------------------
sudo port install freetds
setup.py: Not using bundled FreeTDS
setup.py: include_dirs = ['/usr/local/include', '/opt/local/include', '/opt/local/include/freetds']
setup.py: library_dirs = ['/usr/local/lib', '/opt/local/lib']
running install
running build
running build_ext
building '_mssql' extension
creating build
creating build/temp.macosx-10.6-intel-2.7
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/opt/local/include -I/opt/local/include/freetds -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mssql.c -o build/temp.macosx-10.6-intel-2.7/_mssql.o -DMSDBLIB
_mssql.c:18924:15: error: use of undeclared identifier 'DBVERSION_80'
__pyx_r = DBVERSION_80;
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-KA5ksi/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-A3wRBy-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-KA5ksi/pymssql/
答案 0 :(得分:54)
最高投票解决方案对我不起作用,因为brew没有自己链接旧版本的freetds。我这样做是为了解决这个问题:
brew unlink freetds;
brew install freetds@0.91;
brew link --force freetds@0.91
答案 1 :(得分:37)
我能够通过在运行pip安装之前通过Homebrew恢复到旧版本的FreeTDS来解决这个问题。
brew unlink freetds; brew install homebrew/versions/freetds091
解决方案是由andrewmwhite在: https://github.com/pymssql/pymssql/issues/432
答案 2 :(得分:3)
在http://gree2.github.io/python/setup/2017/04/19/python-instal-pymssql-on-mac上逐步安装pymssql,找到详细而简单的答案。
brew unlink freetds; brew install homebrew/core/freetds091
brew link --force freetds@0.91
pip install pymssql
答案 3 :(得分:1)
" brew install homebrew / python / pymssql"也工作,但将安装旧版2.1.1。
答案 4 :(得分:1)
在@siva和@himanshu解决方法适用于python2
但不适用于python3
之后,我无法从pip3获得成功的构建。
pip3 install pymssql
..._mssql.c:21155:15: error: use of undeclared identifier 'DBVERSION_80'
__pyx_r = DBVERSION_80;
^
1 error generated.
error: command 'clang' failed with exit status 1
您的问题不是许可问题,而是与pymssql
相关代码的代码编译问题。
Here's the discussion, 我在哪里找到Solution on github.
这已经有一段时间了,只是放在这里以提高知名度。
只需使用gitub中最新的pymssql版本:
pip3 install git+https://github.com/pymssql/pymssql
也适用于python2
pip install git+https://github.com/pymssql/pymssql
OR
pip2 install git+https://github.com/pymssql/pymssql
我在Mac OS X (10.13.6) & Homebrew (1.7.1-62-gddbefee)
上进行了多次测试。
该命令适用于两种版本的freetds(0.91)或(1.00.94)
答案 5 :(得分:0)
这在Mac上对我有用:
pip install cython
然后
pip install git+https://github.com/pymssql/pymssql.git
答案 6 :(得分:0)
以上所有解决方案都可以正常工作。提醒您一点,pymssql pip install的setup.py希望Homebrew在/ sw安装了Freetds
if sys.platform == 'darwin':
fink = '/sw'
这不是我机器上的情况,所以我不得不在这里使用工作: