Pip install pygraphviz 失败:pygraphviz 的构建轮失败

Posted

技术标签:

【中文标题】Pip install pygraphviz 失败:pygraphviz 的构建轮失败【英文标题】:Pip install pygraphviz fails: Failed building wheel for pygraphviz 【发布时间】:2017-03-09 01:48:08 【问题描述】:

我在 macOS 10.10.5 上安装 pygraphviz 时遇到问题。我有一个功能齐全的 Python 2.7.x 安装,我想运行 test example of queueing-tool,它需要 installing pygraphviz using pip。

执行命令pip install pygraphviz时,我收到以下冗长的错误消息:

Collecting pygraphviz
  Using cached pygraphviz-1.3.1.zip
Building wheels for collected packages: pygraphviz
  Running setup.py bdist_wheel for pygraphviz ... error
  Complete output from command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/tmpcYcoACpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.10-x86_64-2.7
  creating build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/agraph.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/graphviz.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/release.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/version.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  creating build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_attributes.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz/tests
  running egg_info
  writing pygraphviz.egg-info/PKG-INFO
  writing top-level names to pygraphviz.egg-info/top_level.txt
  writing dependency_links to pygraphviz.egg-info/dependency_links.txt
  warning: manifest_maker: standard file '-c' not found

  reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  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.macosx-10.10-x86_64-2.7/pygraphviz
  copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.10-x86_64-2.7/pygraphviz
  running build_ext
  building 'pygraphviz._graphviz' extension
  creating build/temp.macosx-10.10-x86_64-2.7
  creating build/temp.macosx-10.10-x86_64-2.7/pygraphviz
  clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.10-x86_64-2.7/pygraphviz/graphviz_wrap.o
  pygraphviz/graphviz_wrap.c:3321:12: warning: incompatible pointer to integer conversion returning 'Agsym_t *' (aka 'struct Agsym_s *') from a function with result type 'int' [-Wint-conversion]
      return agattr(g, kind, name, val);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
  pygraphviz/graphviz_wrap.c:3405:7: warning: unused variable 'fd1' [-Wunused-variable]
    int fd1 ;
        ^
  pygraphviz/graphviz_wrap.c:3406:13: warning: unused variable 'mode_obj1' [-Wunused-variable]
    PyObject *mode_obj1 ;
              ^
  pygraphviz/graphviz_wrap.c:3407:13: warning: unused variable 'mode_byte_obj1' [-Wunused-variable]
    PyObject *mode_byte_obj1 ;
              ^
  pygraphviz/graphviz_wrap.c:3408:9: warning: unused variable 'mode1' [-Wunused-variable]
    char *mode1 ;
          ^
  pygraphviz/graphviz_wrap.c:3463:7: warning: unused variable 'fd2' [-Wunused-variable]
    int fd2 ;
        ^
  pygraphviz/graphviz_wrap.c:3464:13: warning: unused variable 'mode_obj2' [-Wunused-variable]
    PyObject *mode_obj2 ;
              ^
  pygraphviz/graphviz_wrap.c:3465:13: warning: unused variable 'mode_byte_obj2' [-Wunused-variable]
    PyObject *mode_byte_obj2 ;
              ^
  pygraphviz/graphviz_wrap.c:3466:9: warning: unused variable 'mode2' [-Wunused-variable]
    char *mode2 ;
          ^
  9 warnings generated.
  clang -bundle -undefined dynamic_lookup build/temp.macosx-10.10-x86_64-2.7/pygraphviz/graphviz_wrap.o -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lcgraph -lcdt -o build/lib.macosx-10.10-x86_64-2.7/pygraphviz/_graphviz.so
  installing to build/bdist.macosx-10.10-x86_64/wheel
  running install
  Trying pkg-config
  Package libcgraph was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libcgraph.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'libcgraph' found
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup.py", line 87, in <module>
      tests_require=['nose>=0.10.1', 'doctest-ignore-unicode>=0.1.0',],
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
      dist.run_commands()
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
      self.run_command(cmd)
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python2.7/site-packages/wheel/bdist_wheel.py", line 215, in run
      self.run_command('install')
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
      self.distribution.run_command(command)
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
      cmd_obj.run()
    File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_commands.py", line 44, in modified_run
      self.include_path, self.library_path = get_graphviz_dirs()
    File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_extra.py", line 121, in get_graphviz_dirs
      include_dirs, library_dirs = _pkg_config()
    File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_extra.py", line 44, in _pkg_config
      output = S.check_output(['pkg-config', '--libs-only-L', 'libcgraph'])
    File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 574, in check_output
      raise CalledProcessError(retcode, cmd, output=output)
  subprocess.CalledProcessError: Command '['pkg-config', '--libs-only-L', 'libcgraph']' returned non-zero exit status 1

  ----------------------------------------
  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
    Complete output from command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-7HXgN6-record/install-record.txt --single-version-externally-managed --compile:
    running install
    Trying pkg-config
    Package libcgraph was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcgraph.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libcgraph' found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup.py", line 87, in <module>
        tests_require=['nose>=0.10.1', 'doctest-ignore-unicode>=0.1.0',],
      File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_commands.py", line 44, in modified_run
        self.include_path, self.library_path = get_graphviz_dirs()
      File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_extra.py", line 121, in get_graphviz_dirs
        include_dirs, library_dirs = _pkg_config()
      File "/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup_extra.py", line 44, in _pkg_config
        output = S.check_output(['pkg-config', '--libs-only-L', 'libcgraph'])
      File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 574, in check_output
        raise CalledProcessError(retcode, cmd, output=output)
    subprocess.CalledProcessError: Command '['pkg-config', '--libs-only-L', 'libcgraph']' returned non-zero exit status 1

    ----------------------------------------
Command "/usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-7HXgN6-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/x3/nr48r8q10dv1lb9l9t_yx7kh0000gq/T/pip-build-Ljj4Ox/pygraphviz/

我不确定如何解决上述错误。所有其他 Python 包,例如 numpy 或 networkx,都可以直接安装。任何帮助将不胜感激。提前非常感谢。

【问题讨论】:

原因是:在 pkg-config 搜索路径中找不到包 libcgraph。也许您应该将包含 `libcgraph.pc' 的目录添加到 PKG_CONFIG_PATH 环境变量中。您可以使用谷歌找到解决方案。 你安装了 libcgraph 吗? 【参考方案1】:

基本上你需要先用brew下载graphviz

brew install graphviz

pip install graphviz

pip install pygraphviz 

您也可以尝试使用pip3 代替pip,以防万一出现Python 的版本问题。希望对您有所帮助。

【讨论】:

【参考方案2】:

试试这个:

sudo apt-get install python-dev graphviz libgraphviz-dev pkg-config

如果您使用的是 Python 3,则可能需要以下内容:

sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config

然后

sudo pip install pygraphviz

【讨论】:

这不是 MacOS 的解决方案!但它可能适用于 Debian 或衍生产品... 如果我不能运行apt-get怎么办? 这在 Ubuntu 18.04 和 Python 3.9 上对我不起作用 这就是问题所在。您首先需要实际的程序。如果开发者有错误提醒用户这样做,那就太好了。【参考方案3】:

安德鲁的评论让我走上了正确的道路。谢谢你。

事实证明,在 macOS 上安装 pygraphviz 的详细解决方案已经在 *** 上提供,参见this solution by teut。

【讨论】:

以上是关于Pip install pygraphviz 失败:pygraphviz 的构建轮失败的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 pip 安装 pygraphviz

python -m pip install --upgrade pip升级失败

python -m pip install --upgrade pip 安装失败

python使用pip install 库名下载失败解决

pip install enable 失败

pip install mysqlclient 安装失败