Python 看不到 pygraphviz
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15661384/
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
Python does not see pygraphviz
提问by Sashko Lykhenko
I have installed pygraphviz using easy_install But when i launch python i have an error:
我已经使用 easy_install 安装了 pygraphviz 但是当我启动 python 时出现错误:
>>>import pygraphviz as pgv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygraphviz
>>>
Using Ubuntu 12.04 and gnome-terminal.
使用 Ubuntu 12.04 和 gnome-terminal。
采纳答案by Sidharth Shah
Assuming that you're on Ubuntu please look at following steps
假设您使用的是 Ubuntu,请查看以下步骤
sudo apt-get install graphviz libgraphviz-dev pkg-config- Create and activate virtualenvif needed. The commands looks something like
sudo apt-get install python-pip python-virtualenv - Run
pip install pygraphviz - Run terminal and check by importing and see if it works
sudo apt-get install graphviz libgraphviz-dev pkg-config- 如果需要,创建并激活virtualenv。命令看起来像
sudo apt-get install python-pip python-virtualenv - 跑
pip install pygraphviz - 运行终端并通过导入检查并查看它是否有效
回答by Sean
The quick and easy solution is:
快速简便的解决方案是:
sudo apt-get install -y python-pygraphviz
using pip will also work, but make sure you have graphviz, libgraphviz-dev, and pkg-config already installed.
使用 pip 也可以,但请确保您已经安装了 graphviz、libgraphviz-dev 和 pkg-config。
sudo apt-get install -y graphviz libgraphviz-dev pkg-config python-pip
sudo pip install pygraphviz
回答by CPBL
Under Ubuntu 15.10+ (ie 2015ish Debian), the quick and easy solution is:
在 Ubuntu 15.10+(即 2015ish Debian)下,快速简便的解决方案是:
sudo apt-get install python-pygraphviz
Any dependencies are properly pulled by apt.
任何依赖项都由 apt 正确拉取。
回答by Bart Theeten
On Mac OSX, the following did the trick for me:
在 Mac OSX 上,以下对我有用:
pip install graphviz
pip install cgraph
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
cd /usr/local/include/graphviz
sudo ln -s . graphviz
pip install pygraphviz
[As suggested, fixed typo from previously /urs/local/ to /usr/local/]
[按照建议,将以前的 /urs/local/ 错字修正为 /usr/local/]
回答by Alp Celik
On Mac OSX El Capitan, Bart Theeten's solution works but there are two things you need to be careful. Initially, make sure that you installed graphviz on your computer. You can use homebrew:
在 Mac OSX El Capitan 上,Bart Theeten 的解决方案有效,但您需要注意两件事。最初,请确保您在计算机上安装了 graphviz。您可以使用自制软件:
brew install graphviz
Other thing is to make sure you add the path of packages to PYTHONPATH
另一件事是确保将包的路径添加到 PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/
回答by Alp Celik
On Ubuntu 14.04, there is a problem in auto detecting graphviz library and include files. If you follow the steps below probably you'll be safe.
在 Ubuntu 14.04 上,自动检测 graphviz 库和包含文件存在问题。如果您按照以下步骤操作,您可能会很安全。
1) sudo apt-get install graphviz libgraphviz-dev pkg-config python-pip
2) pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/"

