python版的igraph各種安裝不成功?請往下看
不能用pip install igraph 會導致報錯,提示名字是jgraph,需要改名。
安裝後,無法可視化?這是因爲你沒有安裝依賴包。
pip install python-igraph 這是官方方式,如果你照此安裝成功後,進行代碼測試時,提示你 無法找到--version-- 那麼請使用手動安裝辦法。
1. 首先卸載之前的: pip uninstall python-igraph
2.根據自己的python版本和計算機位數找python_igraph和pycairo的輪子, https://www.lfd.uci.edu/~gohlke/pythonlibs/
比如我python版本是3.7.6,計算機是64位的,那麼就應該下載:
3.之後用conda額命令行,在下載路徑下執行
pip install pycairo-1.19.1-cp37-cp37m-win_amd64.whl
pip install python_igraph-0.7.1.post6-cp37-cp37m-win_amd64.whl
4.安裝完畢後關閉命令行
5.打開conda的jupyter
6進行測試:
import igraph
print(igraph.__version__)
%matplotlib inline
import igraph as ig
import networkx as nx
import matplotlib.pylab as plt
_edges = [
(1, 2),
(3, 4), (3, 5), (3, 6), (3, 8),
(4, 5), (4, 6), (4, 7), (4, 8),
(5, 6), (5, 7), (5, 8),
(6, 7), (6, 8),
(7, 8)
]
G = nx.Graph()
for e in _edges:
G.add_edge(e[0], e[1], weight = 1)
pos = nx.spring_layout(G)
plt.figure()
plt.axis('off')
nx.draw_networkx_edges(G, pos, edge_color='r')
nx.draw_networkx_nodes(G, pos, alpha=0.8, node_size=400, node_color='w', scale=100)
nx.draw_networkx_labels(G, pos, font_size=12)
plt.show()