简单的在windows安装pygraphiviz的过程如下:
1. 首先安装graphviz, http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.28.0.msi
2. 下载pygraphviz源码包, http://pypi.python.org/packages/source/p/pygraphviz/pygraphviz-1.1.zip
3. 解压后
1. 修改setup.py,三个地方要改
library_path=r'D:\Program Files (x86)\Graphviz 2.28\lib\release\lib' #按你的graphviz路径修改
include_path=r'D:\Program Files (x86)\Graphviz 2.28\include\graphviz' #按你的graphviz路径修改
2. 修改文件unixcompiler.py,一般是285行(“C:\python27\lib\distutils\unixcompiler.py")如下:
old: compiler = os.path.basename(sysconfig.get_config_var("CC"))
new: compiler = "gcc"
编译完pygraphviz后,记得改回去。
4. python setup.py build -c mingw32 要先确定已安装mingw32
5. 手工拷贝pygraphviz目录(像:D:\Downloads\pygraphviz\build\lib.win32-2.7) 到python的site-packages下:C:\Python27\Lib\site-packages
6. 检查下是否安装成功
import pygraphviz
按上述方法基本就可以安装成功。
但是,我在这个过程中碰见如下几个问题:
1. 尝试用python setup.py build -c mingw32的时候,碰到:gcc: 错误:unrecognized command line option ‘-mno-cygwin’
错误如下:
running build_ext
building 'pygraphviz._graphviz' extension
d:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-ID:\Program Files (x86)\Graphviz 2.28\include\grap
hviz" -ID:\Python\Python27\include -ID:\Python\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\te
mp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
gcc: 错误:unrecognized command line option ‘-mno-cygwin’
error: command 'gcc' failed with exit status 1
原因:
mingw版本太新了...无语...找了个老版本的mingw32就可以了。
2. 编译过程中,碰见:cannot find -lcgraph
错误如下:
D:\Downloads\pygraphviz>python setup.py build -c mingw32
elease\libth=D:\Program Files (x86)\Graphviz 2.28\lib
include_path=D:\Program Files (x86)\Graphviz 2.28\include\graphviz
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-ID:\Program Files (x86)\Graphviz 2.28\include\grap
hviz" -ID:\Python\Python27\include -ID:\Python\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\te
mp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855: warning: return makes integer from pointer without a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
elease\lib" -LD:\Python\Python27\libs -LD:\Python\Python27\PCbuild "-Wl,-RD:\Program Files (x86)\Gra
elease\lib" -lcgraph -lcdt -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pygraphviz\_graphviz.pyd
c:/mingw/bin/../lib/gcc/mingw32/4.4.1/http://www.cnblogs.com/http://www.cnblogs.com/mingw32/bin/ld.exe: cannot find -lcgraph
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
原因:
library_path没有设置对。这个要说起windows路径的问题。如果我们把一个路径赋值给一个字符串的时候,简单说有两种
办法保持路径不会被转义或者截断:
1. 使用原始字符串r:
library_path=r'D:\Program Files (x86)\Graphviz 2.28\lib\release\lib'
include_path=r'D:\Program Files (x86)\Graphviz 2.28\include\graphviz'
2. 自己把'\'改为'\\':
library_path='D:\\Program Files (x86)\\Graphviz 2.28\\lib\\release\\lib'
include_path='D:\\Program Files (x86)\\Graphviz 2.28\\include\\graphviz'
3. 测试是否安装成功的时候,发现:ImportError: No module named _graphviz
错误如下:
D:\Downloads\pygraphviz>python
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygraphviz
Traceback (most recent call last):
File "", line 1, in
File "pygraphviz\__init__.py", line 54, in
from agraph import AGraph, Node, Edge, Attribute, ItemAttribute
File "pygraphviz\agraph.py", line 19, in
import graphviz as gv
File "pygraphviz\graphviz.py", line 7, in
import _graphviz
ImportError: No module named _graphviz
原因:
不要运行python命令在pygraphviz目录下,随便新开个cmd窗口,再次运行python命令并且尝试import,这下就可以了。
1. 修改setup.py,三个地方要改
library_path=r'D:\Program Files (x86)\Graphviz 2.28\lib\release\lib' #按你的graphviz路径修改
include_path=r'D:\Program Files (x86)\Graphviz 2.28\include\graphviz' #按你的graphviz路径修改
2. 修改文件unixcompiler.py,一般是285行(“C:\python27\lib\distutils\unixcompiler.py")如下:
old: compiler = os.path.basename(sysconfig.get_config_var("CC"))
new: compiler = "gcc"
编译完pygraphviz后,记得改回去。
4. python setup.py build -c mingw32 要先确定已安装mingw32
5. 手工拷贝pygraphviz目录(像:D:\Downloads\pygraphviz\build\lib.win32-2.7) 到python的site-packages下:C:\Python27\Lib\site-packages
6. 检查下是否安装成功
import pygraphviz
按上述方法基本就可以安装成功。
但是,我在这个过程中碰见如下几个问题:
1. 尝试用python setup.py build -c mingw32的时候,碰到:gcc: 错误:unrecognized command line option ‘-mno-cygwin’
错误如下:
running build_ext
building 'pygraphviz._graphviz' extension
d:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-ID:\Program Files (x86)\Graphviz 2.28\include\grap
hviz" -ID:\Python\Python27\include -ID:\Python\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\te
mp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
gcc: 错误:unrecognized command line option ‘-mno-cygwin’
error: command 'gcc' failed with exit status 1
原因:
mingw版本太新了...无语...找了个老版本的mingw32就可以了。
2. 编译过程中,碰见:cannot find -lcgraph
错误如下:
D:\Downloads\pygraphviz>python setup.py build -c mingw32
elease\libth=D:\Program Files (x86)\Graphviz 2.28\lib
include_path=D:\Program Files (x86)\Graphviz 2.28\include\graphviz
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-ID:\Program Files (x86)\Graphviz 2.28\include\grap
hviz" -ID:\Python\Python27\include -ID:\Python\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\te
mp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855: warning: return makes integer from pointer without a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
elease\lib" -LD:\Python\Python27\libs -LD:\Python\Python27\PCbuild "-Wl,-RD:\Program Files (x86)\Gra
elease\lib" -lcgraph -lcdt -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pygraphviz\_graphviz.pyd
c:/mingw/bin/../lib/gcc/mingw32/4.4.1/http://www.cnblogs.com/http://www.cnblogs.com/mingw32/bin/ld.exe: cannot find -lcgraph
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
原因:
library_path没有设置对。这个要说起windows路径的问题。如果我们把一个路径赋值给一个字符串的时候,简单说有两种
办法保持路径不会被转义或者截断:
1. 使用原始字符串r:
library_path=r'D:\Program Files (x86)\Graphviz 2.28\lib\release\lib'
include_path=r'D:\Program Files (x86)\Graphviz 2.28\include\graphviz'
2. 自己把'\'改为'\\':
library_path='D:\\Program Files (x86)\\Graphviz 2.28\\lib\\release\\lib'
include_path='D:\\Program Files (x86)\\Graphviz 2.28\\include\\graphviz'
3. 测试是否安装成功的时候,发现:ImportError: No module named _graphviz
错误如下:
D:\Downloads\pygraphviz>python
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygraphviz
Traceback (most recent call last):
File "
File "pygraphviz\__init__.py", line 54, in
from agraph import AGraph, Node, Edge, Attribute, ItemAttribute
File "pygraphviz\agraph.py", line 19, in
import graphviz as gv
File "pygraphviz\graphviz.py", line 7, in
import _graphviz
ImportError: No module named _graphviz
原因:
不要运行python命令在pygraphviz目录下,随便新开个cmd窗口,再次运行python命令并且尝试import,这下就可以了。