首页 > 解决方案 > 在 Windows 10 中安装 pygraphviz - 缺少 basetsd.h

问题描述

我在运行 Python 3.7 的 Windows 10 X64 上安装 pygraphviz 时遇到问题。我使用:pip install graphviz 安装了 graphviz,如下所示: Pip install pygraphviz failed: Failed building wheel for pygraphviz。我不知道要让 pygraphviz 运行需要做什么。任何帮助,将不胜感激。提前致谢。

运行 pip install pygraphviz 时,遇到以下错误:

Microsoft Windows [Version 10.0.18362.836]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\prash>pip install pygraphviz
Collecting pygraphviz
  Using cached https://files.pythonhosted.org/packages/7e/b1/d6d849ddaf6f11036f9980d433f383d4c13d1ebcfc3cd09bc845bda7e433/pygraphviz-1.5.zip
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\prash\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\setup.py'"'"'; __file__='"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\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 'C:\Users\prash\AppData\Local\Temp\pip-wheel-zkrlosp9' --python-tag cp37
       cwd: C:\Users\prash\AppData\Local\Temp\pip-install-pa571k38\pygraphviz\
  Complete output (54 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\agraph.py -> build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\graphviz.py -> build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\release.py -> build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\version.py -> build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\__init__.py -> build\lib.win-amd64-3.7\pygraphviz
  creating build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_attribute_defaults.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_clear.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_drawing.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_edge_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_graph.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_html.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_layout.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_node_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_readwrite.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_setup.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_string.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_subgraph.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\test_unicode.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  copying pygraphviz\tests\__init__.py -> build\lib.win-amd64-3.7\pygraphviz\tests
  running egg_info
  writing pygraphviz.egg-info\PKG-INFO
  writing dependency_links to pygraphviz.egg-info\dependency_links.txt
  writing top-level names to pygraphviz.egg-info\top_level.txt
  reading manifest file 'pygraphviz.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no files found matching '*.png' under directory 'doc'
  warning: no files found matching '*.html' under directory 'doc'
  warning: no files found matching '*.txt' under directory 'doc'
  warning: no files found matching '*.css' under directory 'doc'
  warning: no previously-included files matching '*~' found anywhere in distribution
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files matching '.svn' found anywhere in distribution
  no previously-included directories found matching 'doc\build'
  writing manifest file 'pygraphviz.egg-info\SOURCES.txt'
  copying pygraphviz\graphviz.i -> build\lib.win-amd64-3.7\pygraphviz
  copying pygraphviz\graphviz_wrap.c -> build\lib.win-amd64-3.7\pygraphviz
  running build_ext
  building 'pygraphviz._graphviz' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\pygraphviz
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\prash\Anaconda3\include -IC:\Users\prash\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win-amd64-3.7\Release\pygraphviz/graphviz_wrap.obj
  graphviz_wrap.c
  c:\users\prash\anaconda3\include\pyconfig.h(203): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for pygraphviz
  Running setup.py clean for pygraphviz
Failed to build pygraphviz
Installing collected packages: pygraphviz
  Running setup.py install for pygraphviz ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\prash\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\setup.py'"'"'; __file__='"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\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\prash\AppData\Local\Temp\pip-record-pvkn27t1\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\prash\AppData\Local\Temp\pip-install-pa571k38\pygraphviz\
    Complete output (56 lines):
    running install
    include_dirs=None
    library_dirs=None
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\agraph.py -> build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\graphviz.py -> build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\release.py -> build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\version.py -> build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\__init__.py -> build\lib.win-amd64-3.7\pygraphviz
    creating build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_attribute_defaults.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_clear.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_drawing.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_edge_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_graph.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_html.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_layout.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_node_attributes.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_readwrite.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_setup.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_string.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_subgraph.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\test_unicode.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    copying pygraphviz\tests\__init__.py -> build\lib.win-amd64-3.7\pygraphviz\tests
    running egg_info
    writing pygraphviz.egg-info\PKG-INFO
    writing dependency_links to pygraphviz.egg-info\dependency_links.txt
    writing top-level names to pygraphviz.egg-info\top_level.txt
    reading manifest file 'pygraphviz.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching '*.png' under directory 'doc'
    warning: no files found matching '*.html' under directory 'doc'
    warning: no files found matching '*.txt' under directory 'doc'
    warning: no files found matching '*.css' under directory 'doc'
    warning: no previously-included files matching '*~' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '.svn' found anywhere in distribution
    no previously-included directories found matching 'doc\build'
    writing manifest file 'pygraphviz.egg-info\SOURCES.txt'
    copying pygraphviz\graphviz.i -> build\lib.win-amd64-3.7\pygraphviz
    copying pygraphviz\graphviz_wrap.c -> build\lib.win-amd64-3.7\pygraphviz
    running build_ext
    building 'pygraphviz._graphviz' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\pygraphviz
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\prash\Anaconda3\include -IC:\Users\prash\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win-amd64-3.7\Release\pygraphviz/graphviz_wrap.obj
    graphviz_wrap.c
    c:\users\prash\anaconda3\include\pyconfig.h(203): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\prash\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\setup.py'"'"'; __file__='"'"'C:\\Users\\prash\\AppData\\Local\\Temp\\pip-install-pa571k38\\pygraphviz\\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\prash\AppData\Local\Temp\pip-record-pvkn27t1\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

标签: pythonpython-3.7pygraphviz

解决方案


使用以下步骤在 Windows 10(64 位 python 和 graphviz)上安装 graphviz 和 pygraphviz。

注意:如果您运行的是 64 位 Python,则需要使用 64 位 graphviz。我正在运行 anaconda python 3.8.3(64 位)。

  1. 从此处安装 Microsoft C++ 构建工具: https ://visualstudio.microsoft.com/visual-cpp-build-tools/

  2. 从以下网址下载 64 位 graphviz: https ://github.com/mahkoCosmo/GraphViz_x64/blob/master/graphviz-2.38_x64.tar.gz

  3. 创建 \Graphviz 文件夹:C:\Program Files (x86)\Graphviz

解压tar后,移动Graphviz下的所有文件夹graphviz文件夹(\bin、\etc、\fonts、\gtk-2.0、\include、\lib、\pango、\pkgconfig)

  1. 更新路径以包含:C:\Program Files (x86)\Graphviz\bin

  2. 用户跟随 pip 安装:

    pip install --global-option=build_ext --global-option="-IC:\Program Files (x86)\Graphviz\include" --global-option="-LC:\Program Files (x86)\Graphviz\lib " --no-cache-dir pygraphviz


推荐阅读