pip install pygraphviz:找不到软件包“ libcgraph”


71

我成功安装graphvizcgraph

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

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

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/

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


您在什么操作系统上?
Moses Koledoye

@ MosesKoledoye,macOS Sierra版本10.12
SparkAndShine

1
尝试brew install graphviz-develbrew install pkg-config
摩西Koledoye

Answers:


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

如果您使用的是Python 3,则可能需要执行以下操作:

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

然后

pip install pygraphviz

1
我发现我需要先做sudo apt-get install python-dev,否则我会得到大约缺少一个编译错误,Python.h在做的时候pip install pygraphviz
Brian Stormont

1
如果有人遇到类似问题,我已经更新了python-dev要求。谢谢。
Dhiraj Dhule

第一步,您可以指定所需的python版本:例如sudo apt-get install python3.6-dev。默认值为2.7。另外,使用的第二步sudo给了我一个pip导入错误,但是删除它解决了问题并安装了pygraphviz。
r3robertson

请注意。运行“ sudo pip ...”可能不是一个好主意。最好将pip保留为虚拟环境的一部分,如果没有,则只需以常规用户身份运行pip。见stackoverflow.com/questions/21055859/…–
哈林

45

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

$ brew install graphviz
$ sudo pip install pygraphviz 

4
我使用了virtualenv和Python 3,并且pip install graphviz无需任何其他选项就可以运行,并且工作正常(在之后brew install graphviz)。
特伦顿

哦,谢谢。非常感谢。你救了我的一天,我的屁股被踢了。:)
Jyotirmay'7

按照@Trenton的说明-pip install graphviz运行后,我发现所有要求都得到满足,brew install graphviz并且brew安装在字体上暂停了很长时间。
罗布


6

在macOS上,我做到了,

$ brew install graphviz
$ sudo pip install pygraphviz

没为我工作。安装graphviz之后,我必须下载pygraphviz的git项目并使用sudo python3 setup.py install --include-path=/usr/local/Cellar/graphviz/2.40.1/include/graphviz --library-path=/usr/local/Cellar/graphviz/2.40.1/lib
Itay

2

对于CentOS。由于需要graphviz-devel来解决此问题,因此您需要使用yum进行安装。为此,您需要在仓库可用的地方添加仓库。以我为例,原子存储库工作正常。

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

这将添加原子仓库,然后

sudo yum install graphviz-devel

而且您应该能够执行

pip install pygraphviz

0

在使用python-alpine映像为Django创建Dockerfile时遇到了这个问题。

由于这篇博文添加了“ graphviz-dev”包以及我的应用程序的其他依赖项,因此我能够解决它。

例:

#Install dependencies
RUN apk add --update --no-cache --virtual .build-deps \
    build-base \
    alpine-sdk \
    postgresql-dev \
    libffi-dev \
    python3-dev \
    libffi-dev \
    jpeg-dev \
    zlib-dev \
    musl-dev \
    libpq \
    graphviz-dev \  
    && pip install --no-cache-dir -r /code/requirements_dev.txt \
    && find /usr/local \
        \( -type d -a -name test -o -name tests \) \
        -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
        -exec rm -rf '{}' +

问候

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.