在 Linux 上安装 pyodbc 失败

use*_*502 4 python

我只是运行这个命令:

\n\n
sudo pip install pyodbc   \n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n
steven81@PythonWEBVM:~$ sudo pip install pyodbc\nThe 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.\nThe 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.\nCollecting pyodbc\n  Downloading https://files.pythonhosted.org/packages/aa/71/cef225c4889620a1a00251d24c1746fe0cf4124290a75d1c2dc5c187b61f/pyodbc-4.0.23.tar.gz (215kB)\n    100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 225kB 13.5MB/s\nInstalling collected packages: pyodbc\n  Running setup.py install for pyodbc ... error\n    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(\'\\r\\n\', \'\\n\');f.close();exec(compile(code, __file__, \'exec\'))" install --record /tmp/pip-record-voJYBN/install-record.txt --single-version-externally-managed --compile:\n    running install\n    running build\n    running build_ext\n    building \'pyodbc\' extension\n    creating build\n    creating build/temp.linux-x86_64-2.7\n    creating build/temp.linux-x86_64-2.7/src\n    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\n    cc1plus: warning: command line option \xe2\x80\x98-Wstrict-prototypes\xe2\x80\x99 is valid for C/ObjC but not for C++\n    In file included from src/pyodbcmodule.cpp:11:0:\n    src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory\n    compilation terminated.\n    error: command \'x86_64-linux-gnu-gcc\' failed with exit status 1\n\n    ----------------------------------------\nCommand "/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(\'\\r\\n\', \'\\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/  \n
Run Code Online (Sandbox Code Playgroud)\n\n

我看到有一个错误:

\n\n

命令 \'x86_64-linux-gnu-gcc\' 失败,退出状态为 1\n然后我在 google 上搜索,它要求运行以下命令:

\n\n
sudo apt-get install python-dev\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n
steven81@PythonWEBVM:~$ sudo apt-get install python-dev\nReading package lists... Done\nBuilding dependency tree\nReading state information... Done\npython-dev is already the newest version (2.7.12-1~16.04).\n0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.    \n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n

小智 5

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

sudo apt-get install unixodbc-dev

sudo apt-get install python3-dev

python3 -m pip 安装 pyodbc

  • 在 venv 下不起作用。我已经在 venv 之外安装了所有内容,但看起来它们没有转移到 venv 中。Linux 真是一个玩起来的野兽...... (2认同)