在 Windows 上使用 Python 3.7 安装 pycairo

Intalling pycairo with Python 3.7 on Windows

我正在尝试安装 pycairo,尽管我在 Internet 上找到了一些东西,但我还是没能成功

我确实 pip install pycairo,但它要求我安装 Visual Basic Build Tool。我做到了,但它不起作用。我尝试了很多在网络上找到的想法(例如这个网站https://www.lfd.uci.edu/~gohlke/pythonlibs/),但也没有用。

当我尝试 pip install pycairo 时,错误消息是:

Collecting pycairo
  Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Installing collected packages: pycairo
  Running setup.py install for pycairo ... error
    ERROR: Command errored out with exit status 1:
     command: 'd:\programmes\python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\setup.py'"'"'; __file__='"'"'C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\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\Thomas\AppData\Local\Temp\pip-record-6wtp6mn1\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\
    Complete output (18 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\cairo
    copying cairo\__init__.py -> build\lib.win-amd64-3.7\cairo
    copying cairo\__init__.pyi -> build\lib.win-amd64-3.7\cairo
    copying cairo\py.typed -> build\lib.win-amd64-3.7\cairo
    running build_ext
    building 'cairo._cairo' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\cairo
    C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.21.27702\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=18 -DPYCAIRO_VERSION_MICRO=1 -Id:\programmes\python\include -Id:\programmes\python\include "-IC:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.21.27702\include" "-IC:\Program Files (x86)\Windows Kits\include.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17763.0\cppwinrt" /Tccairo/device.c /Fobuild\temp.win-amd64-3.7\Release\cairo/device.obj
    device.c
    C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\cairo\pycairo.h(37): fatal error C1083: Impossible d'ouvrir le fichier includeÿ: 'cairo.h'ÿ: No such file or directory
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x64\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\programmes\python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\setup.py'"'"'; __file__='"'"'C:\Users\Thomas\AppData\Local\Temp\pip-install-58_68_s2\pycairo\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\Thomas\AppData\Local\Temp\pip-record-6wtp6mn1\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

而且我不明白!

在 Windows 上安装库可能有点困难。 我通常使用这个网站: https://www.lfd.uci.edu/~gohlke/pythonlibs/

然后,搜索您的包(此处:pycairo‑1.18.1‑cp37‑cp37m‑win_amd64.whl)

然后,在下载文件的文件夹中启动 cmd,并执行:

pip install pycairo‑1.18.1‑cp37‑cp37m‑win_amd64.whl

希望对您有所帮助!