在 Linux 上安装 pyodbc 失败



我只是运行以下命令:

sudo pip install pyodbc   

然后我得到以下消息和错误:

steven81@PythonWEBVM:~$ sudo pip install pyodbc
The directory '/home/steven81/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/steven81/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyodbc
Downloading https://files.pythonhosted.org/packages/aa/71/cef225c4889620a1a00251d24c1746fe0cf4124290a75d1c2dc5c187b61f/pyodbc-4.0.23.tar.gz (215kB)
100% |████████████████████████████████| 225kB 13.5MB/s
Installing collected packages: pyodbc
Running setup.py install for pyodbc ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-NR7ytY/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-voJYBN/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DPYODBC_VERSION=4.0.23 -I/usr/include/python2.7 -c src/pyodbcmodule.cpp -o build/temp.linux-x86_64-2.7/src/pyodbcmodule.o -Wno-write-strings
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from src/pyodbcmodule.cpp:11:0:
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-NR7ytY/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-voJYBN/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-NR7ytY/pyodbc/  

我看到有一个错误:

命令"x86_64-linux-gnu-gcc"失败,退出状态为 1 然后我在谷歌上搜索,它要求运行这个:

sudo apt-get install python-dev

所以,我运行这个,但得到以下消息:

steven81@PythonWEBVM:~$ sudo apt-get install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version (2.7.12-1~16.04).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.    

那么问题是什么以及如何正确安装 pyodbc?

对于任何寻找pyodbc安装以从Linux(ubuntu(连接到SQLServer的人。

sudo apt-get install unixodbc-dev

sudo apt-get install python3-dev

python3 -m pip install pyodbc

最新更新