无法在 Windows 10 中使用 python 3.10 安装 pyodbc

uma*_*ood 12 django odbc pyodbc python-3.x

当我尝试安装 Pyodbc 时出现此错误,我已经安装了 Visual Studio 并且我的计算机中安装了 Microsoft Visual C++ 12 、 15-19 ,但仍然出现此错误。

Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: sqlparse, pytz, asgiref, pyodbc, Django, Pillow, mssql-django, django-crispy-forms
    Running setup.py install for pyodbc ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"'; __file__='"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\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 'C:\Users\Athar\AppData\Local\Temp\pip-record-t1td50y6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\include\site\python3.10\pyodbc'
         cwd: C:\Users\Athar\AppData\Local\Temp\pip-install-w0wwm18g\pyodbc_61963e883a8543fea24a63b1c522bbea\
    Complete output (7 lines):
    running install
    C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_ext
    building 'pyodbc' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"'; __file__='"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\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 'C:\Users\Athar\AppData\Local\Temp\pip-record-t1td50y6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\include\site\python3.10\pyodbc' Check the logs for full command output.
Run Code Online (Sandbox Code Playgroud)

Gor*_*son 26

更新 - 2022 年 11 月 22 日:

\n
    \n
  1. pyodbc 4.0.34 开始为 Python 3.10 提供 Windows 轮文件。pyodbc 4.0.35开始为Python 3.11提供wheel文件(包括Windows)。TL;DR -pip install pyodbc应该在 Windows 上“正常工作”,适用于 64 位和 32 位 Python。

    \n
  2. \n
  3. Christoph 在www.lfd.uci.edu上的车轮档案显然不再更新。

    \n
  4. \n
\n
\n

(原答案)

\n

当前版本的 pyodbc (4.0.32) 没有针对 Python 3.10 的预构建 Wheel 文件。目前安装它的最简单方法是从以下位置下载适当的轮子

\n

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc

\n

然后安装它。例如,如果您正在运行 64 位 Python,那么您将下载 64 位轮并使用

\n
pip install pyodbc\xe2\x80\x914.0.32\xe2\x80\x91cp310\xe2\x80\x91cp310\xe2\x80\x91win_amd64.whl\n
Run Code Online (Sandbox Code Playgroud)\n