首页 > 解决方案 > 如何在服务器中安装 pyodbc python 库?

问题描述

我有 python 3.8,我正在尝试安装 pyodbc 库来连接 sql server 但出现错误。请帮我怎么安装?有没有其他库可以连接sql server?

我正在使用以下命令 -

python3 -m pip install pyodbc

我得到的错误 -

Collecting pyodbc
  Using cached pyodbc-4.0.30.tar.gz (266 kB)
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-67s6uwc7
       cwd: /tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/
  Complete output (10 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'pyodbc' extension
  creating build
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/src
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/app/python3.7.4/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
  gcc: error trying to exec 'cc1plus': execvp: No such file or directory
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyodbc
  Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pyodbc
    Running setup.py install for pyodbc ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/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-w_eqzv_4/install-record.txt --single-version-externally-managed --compile --install-headers /app/python3.7.4/include/python3.7m/pyodbc
         cwd: /tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/
    Complete output (10 lines):
    running install
    running build
    running build_ext
    building 'pyodbc' extension
    creating build
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/src
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/app/python3.7.4/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
    gcc: error trying to exec 'cc1plus': execvp: No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fnygoose/pyodbc_7db1b044e510447c8352fe2f54d4cbe0/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-w_eqzv_4/install-record.txt --single-version-externally-managed --compile --install-headers /app/python3.7.4/include/python3.7m/pyodbc Check the logs for full command output.

标签: pythonpython-3.xpyodbcpypyodbc

解决方案


您需要安装第一个依赖项。

!apt install unixodbc-dev --yes
!pip install pyodbc

推荐阅读