【问题标题】:"Microsoft Visual C++ … is required" error when trying to install pyodbc on Windows尝试在 Windows 上安装 pyodbc 时出现“需要 Microsoft Visual C++ ...”错误
【发布时间】:2019-01-08 23:07:27
【问题描述】:

我正在尝试安装 pyodbc,但出现以下错误。

C:\Python\Python37\Scripts>pip3 install pyodbc

输出

Collecting pyodbc
  Using cached https://files.pythonhosted.org/packages/aa/71/cef225c4889620a1a00251d24c1746fe0cf4124290a75d1c2dc5c187b61f/pyodbc-4.0.23.tar.gz
Installing collected packages: pyodbc
  Running setup.py install for pyodbc ... error
    Complete output from command c:\python\python37\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Alankar\\AppData\\Local\\Temp\\pip-install-7qf14pkz\\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 C:\Users\Alankar\AppData\Local\Temp\pip-record-k11gmg0x\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'pyodbc' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

Command "c:\python\python37\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Alankar\\AppData\\Local\\Temp\\pip-install-7qf14pkz\\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 C:\Users\Alankar\AppData\Local\Temp\pip-record-k11gmg0x\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Alankar\AppData\Local\Temp\pip-install-7qf14pkz\pyodbc\

【问题讨论】:

  • Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools"
  • 请重新格式化您的问题。

标签: python python-3.x windows pip pyodbc


【解决方案1】:

我无法让 C++ 构建工具方法工作,但我发现此方法非常简单:

  1. 根据你电脑的架构和Python版本下载相关的pyodbc轮子(预编译二进制):https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc
  2. 运行pip install <wheel path>

例如:

pip install c:\users\bob\downloads\pyodbc-4.0.27-cp38-cp38-win_amd64.whl

【讨论】:

  • 这是一个很好的解决方法,例如当前的 pyodbc 4.0.27 和 Python 3.8 情况。 pyodbc 的下一个版本很可能包含 Python 3.8 的官方轮子,它将启用 pip install pyodbc
  • 太棒了。它对我有用。非常感谢
【解决方案2】:

某些库需要 C++ 构建工具才能安装。在您的情况下,要解决此问题,有两种方法:

更新 pip 的设置工具:

要修复您的错误,请通过以下命令更新设置工具:

pip install --upgrade setuptools

第二种方法是:

安装 Microsoft Visual C++ 构建工具

这也可以通过安装微软提供的这个小工具来解决: https://visualstudio.microsoft.com/visual-cpp-build-tools/

【讨论】:

  • 我采用了第二种方法,它奏效了。谢谢。
【解决方案3】:

即使在我安装了 Microsoft VC++ 构建工具之后,我的机器上的安装也失败了,我的解决方案是安装早期版本。较新版本假定您已安装 VC++ 和 VS 2019。

运行这个命令

pip install -Iv pyodbc==4.0.27

【讨论】:

    【解决方案4】:

    如果其他答案均无效: 我正在运行最新版本的 python,它给了我这个错误。 一旦我降级到 3.8.x,它就像使用 pip install 的魅力一样

    【讨论】:

      猜你喜欢
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 2018-04-25
      • 1970-01-01
      • 2020-08-08
      相关资源
      最近更新 更多