Python下使用IGraph初探
1、环境的配置
下载下面的包并安装
- Python 2.6 Installer – python-2.6.2.msi – From http://www.python.org/download/ – This is installer for the core Python and IDLE IDE installer. I am using Python 2.6 as the other required packages do not currently support later versions of Python (like Python 3).(一般情况下你已经安装)
- wxPython 2.8 Installer – wxPython2.8-win32-unicode-2.8.10.1-py26.exe – From http://www.wxpython.org/download.php – This is the installer for the cross-platform wxPython GUI library.
- wxPython 2.8 Docs and Demos Installer – wxPython2.8-win32-docs-demos-2.8.10.1.exe – From http://www.wxpython.org/download.php – This is the installer for documentation and demo code for the wxPython GUI library.
- pyCairo 1.8 Installer – pycairo-1.8.4.win32-py2.6.exe – From http://wxpython.org/cairo/ – This is the installer for the pyCairo package that wraps the Cairo DLL.
- Cairo DLL – cairo_1.8.6-1_win32.zip – From http://wxpython.org/cairo/ – This is a Zip file containing the Cairo DLL.
- libpng DLL – libpng_1.2.34-1_win32.zip – From http://wxpython.org/cairo/ – This is a Zip file containing the libpng DLL that the Cairo DLL depends on.
- zlib DLL – zlib123-dll.zip – From http://wxpython.org/cairo/ – This is a Zip file containing the zlib DLL that the Cairo DLL depends on.
按照下面的步骤安装 (feel free not to if you know what you’re doing):
- Double-click on, run python-2.6.2.msi and agree to all defaults. This will install the Python interpreter in C:\Python26\.
- Double-click on, run wxPython2.8-win32-unicode-2.8.10.1-py26.exe and agree to all defaults. This will install the wxPython package to C:\Python26\Lib\site-packages\wx-2.8-msw-unicode\
- Double-click on, run wxPython2.8-win32-docs-demos-2.8.10.1.exe and agree to all defaults. This will install the docs and demos for wxPython to C:\Program Files\wxPython2.8 Docs and Demos\
- Double-click on, run pycairo-1.8.4.win32-py2.6.exe and agree to all defaults. This will install the pyCairo Python wrapper package for Cairo to C:\Python26\Lib\site-packages\cairo\
- Open cairo_1.8.6-1_win32.zip and extract only bin\libcairo-2.dll to C:\Python26\Lib\site-packages\cairo\libcairo-2.dll (note that the folder in the above path is “Lib”, not “libs”)
- Open zlib123-dll.zip and extract only zlib1.dll to C:\Python26\Lib\site-packages\cairo\zlib1.dll
- Open libpng_1.2.34-1_win32.zip and extract only bin\libpng12-0.dll to C:\Python26\Lib\site-packages\cairo\libpng12-0.dll
最后你的Lib\site-packages\cairo文件夹下应该是这样的:
- __init__.py
- __init__.pyc
- __init__.pyo
- _cairo.pyd
- libcairo-2.dll
- libpng12-0.dll
- zlib1.dll
2、测试是否成功
>>> from igraph import *
>>> g = Graph.Famous("petersen")
>>> plot(g)