【发布时间】:2020-01-11 17:49:13
【问题描述】:
尽管安装了 apt-installed libcairo2-dev 和 pip-installed cairocffi,但我无法在 Google Colab 中使用 python-igraph 绘制任何内容。
我想在 Colab 的一个项目中使用 igraph,专门用于绘制图形和节点社区。安装步骤顺利进行,没有错误。但是当我尝试绘制一个简单的图形时,我收到来自igraph/drawing/__init__.py 的关于 utf-8 编码的错误。将pycairo 换成cairocffi 后,我得到了同样的错误。
!sudo apt install build-essential python-dev libxml2 libxml2-dev zlib1g-dev libcairo2-dev
!pip install cairocffi python-igraph
import igraph as ig
g = ig.Graph(edges=[(0,1)])
ig.plot(g)
没有情节出现,我得到:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
336 method = get_real_method(obj, self.print_method)
337 if method is not None:
--> 338 return method()
339 return None
340 else:
/usr/local/lib/python3.6/dist-packages/igraph/drawing/__init__.py in _repr_svg_(self)
352 surface.finish()
353 # Return the raw SVG representation
--> 354 return io.getvalue().encode("utf-8")
355
356 @property
AttributeError: 'bytes' object has no attribute 'encode'
<igraph.drawing.Plot at 0x7f6b34afb160>
【问题讨论】:
标签: python igraph google-colaboratory