Python pip install pygraphviz:找不到包“libcgraph”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40528048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:37:39  来源:igfitidea点击:

pip install pygraphviz: No package 'libcgraph' found

pythonmacosinstallpippygraphviz

提问by SparkAndShine

I succeed in installing graphvizand cgraphwith

我成功安装graphvizcgraph使用

$ sudo pip install graphviz
....
Successfully installed graphviz-0.5.1

$ sudo pip install cgraph
...
Successfully installed cgraph-0.1

I encounter the issue No package 'libcgraph' foundwhile running sudo pip install pygraphviz. Below is the full stacktrace.

No package 'libcgraph' found在运行时遇到了这个问题sudo pip install pygraphviz。以下是完整的堆栈跟踪。

$ sudo pip install pygraphviz
The directory '/Users/sparkandshine/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/sparkandshine/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygraphviz
  Downloading pygraphviz-1.3.1.zip (123kB)
    100% |████████████████████████████████| 133kB 1.5MB/s 
Installing collected packages: pygraphviz
  Running setup.py install for pygraphviz ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-qfFpFG/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 /tmp/pip-JmwjA6-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/tmp/pip-build-qfFpFG/pygraphviz/setup.py", line 87, in <module>
        tests_require=['nose>=0.10.1', 'doctest-ignore-unicode>=0.1.0',],
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "setup_commands.py", line 44, in modified_run
        self.include_path, self.library_path = get_graphviz_dirs()
      File "setup_extra.py", line 121, in get_graphviz_dirs
        include_dirs, library_dirs = _pkg_config()
      File "setup_extra.py", line 44, in _pkg_config
        output = S.check_output(['pkg-config', '--libs-only-L', 'libcgraph'])
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, 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/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-qfFpFG/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 /tmp/pip-JmwjA6-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-qfFpFG/pygraphviz/

I tried the solutions provided by Python does not see pygraphviz, but it doesn't work.

我尝试了Python提供的解决方案没有看到 pygraphviz,但它不起作用。

回答by Dhiraj Dhule

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

or the following might be needed if you're using Python 3:

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

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

then

然后

pip install pygraphviz

回答by Rob

For MacOS, I needed to do:

对于 MacOS,我需要执行以下操作:

$ brew install graphviz
$ sudo pip install pygraphviz 

回答by Edouard Amosse

For fedora users:

对于 Fedora 用户:

  1. yum list available graphviz*
  2. select the appropriate package for your Fedora distribution
  3. sudo yum install 'graphviz-devel.x86_64'
  4. pip install pygraphviz
  1. yum 列表可用 graphviz*
  2. 为您的 Fedora 发行版选择合适的软件包
  3. sudo yum install 'graphviz-devel.x86_64'
  4. pip install pygraphviz

回答by SparkAndShine

On macOS, I made it with,

在 macOS 上,我做到了,

$ brew install graphviz
$ sudo pip install pygraphviz

回答by wolendranh

For CentOS. As graphviz-devel is required to fix this issue, you will need to install it with yum. To do this you are required to add repo's where package is available. In my case Atomicrepos worked fine.

对于 CentOS。由于需要使用 graphviz-devel 来解决此问题,因此您需要使用 yum 安装它。为此,您需要在包可用的地方添加 repo。就我而言,Atomicrepos 工作正常。

wget -q -O - http://www.atomicorp.com/installers/atomic | sh

This will add atomic repos, then

这将添加原子回购,然后

sudo yum install graphviz-devel

And you should be able to perform

你应该能够执行

pip install pygraphviz