如何解决 Ubuntu 20.04 上 pyodbc 的安装错误?

Posted

技术标签:

【中文标题】如何解决 Ubuntu 20.04 上 pyodbc 的安装错误?【英文标题】:How to solve installation error of pyodbc on Ubunutu 20.04? 【发布时间】:2022-01-18 10:34:20 【问题描述】:

我正在尝试在 Ubunut 20.04 (LTS) 上安装 pyodbc 并收到以下错误。

$pip3 install --user pyodbc
Collecting pyodbc
  Using cached pyodbc-4.0.32.tar.gz (280 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/linuxbrew/.linuxbrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-ceo1au72
       cwd: /tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/
  Complete output (9 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'pyodbc' extension
  creating build
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/src
  gcc-5 -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.32 -I/home/linuxbrew/.linuxbrew/include -I/home/linuxbrew/.linuxbrew/opt/openssl@1.1/include -I/home/linuxbrew/.linuxbrew/opt/sqlite/include -I/home/linuxbrew/.linuxbrew/opt/python@3.9/include/python3.9 -c src/buffer.cpp -o build/temp.linux-x86_64-3.9/src/buffer.o -Wno-write-strings
  error: command 'gcc-5' failed: No such file or directory
  ----------------------------------------
  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: /home/linuxbrew/.linuxbrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-m8e62n8n/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/user/.local/include/python3.9/pyodbc
         cwd: /tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/
    Complete output (9 lines):
    running install
    running build
    running build_ext
    building 'pyodbc' extension
    creating build
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/src
    gcc-5 -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.32 -I/home/linuxbrew/.linuxbrew/include -I/home/linuxbrew/.linuxbrew/opt/openssl@1.1/include -I/home/linuxbrew/.linuxbrew/opt/sqlite/include -I/home/linuxbrew/.linuxbrew/opt/python@3.9/include/python3.9 -c src/buffer.cpp -o build/temp.linux-x86_64-3.9/src/buffer.o -Wno-write-strings
    error: command 'gcc-5' failed: No such file or directory
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/linuxbrew/.linuxbrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gn6zk8ei/pyodbc_4351fd17af0242d6b5939cae9874f889/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-m8e62n8n/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/user/.local/include/python3.9/pyodbc Check the logs for full command output.

通过apt 安装gcc-5 不起作用,因为它无法安装。我目前安装了gcc-9 编译器。

我尝试安装 python3-dev python3-pip 如Error installing pandas_profiling with Pip on Ubuntu 20.04 和https://github.com/mkleehammer/pyodbc/wiki/Install#installing-on-linux 中所述,但并没有解决问题。

非常感谢任何帮助。

【问题讨论】:

您正确的 gcc 版本是什么?您是否尝试在运行 pip install 之前设置 CC environemnt 变量? 当前版本是gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0。我会尝试设置这个环境变量:) 【参考方案1】:

From the docs

sudo apt install python3-pip python3-dev unixodbc-dev
pip3 install --user pyodbc

这是针对 18.04 的,但我怀疑它也适合你。

【讨论】:

更好的方法是使用:python3 -m pip install --user pyodbc

以上是关于如何解决 Ubuntu 20.04 上 pyodbc 的安装错误?的主要内容,如果未能解决你的问题,请参考以下文章

在 Ubuntu 20.04 上安装 MySQL 5.6

Ubuntu20.04上3090显卡安装Nvidia驱动和CUDA11.4,cuDNN,anaconda,以及解决向日葵无法连接和重装Ubuntu20.04遇到的问题

如何让 Steam 在 Ubuntu 20.04 上运行

在 Ubuntu 20.04 上安装 R 的最佳方式是啥?

如何在 Ubuntu 20.04 上安装 OpenModelica 1.9.5?

我应该如何在 Ubuntu 20.04 LTS 上安装 Django