近来,在学习python的数据挖掘,需要安装pygraphviz,与诸多麻烦:

注:我的系统是fedora 17beta版;python2.7.3

1、我首先直接安装pygraphviz(easy_install),提示错误:

1) You don't have Graphviz installed:
Install Graphviz (http://graphviz.org)

2) Your Graphviz package might incomplete.
Install the binary development subpackage (e.g. libgraphviz-dev or similar.)

3) You are using Windows
There are no PyGraphviz binary packages for Windows but you might be
able to build it from this source. See
http://networkx.lanl.gov/pygraphviz/reference/faq.html

2、按照以上错误提示,我先安装了Graphviz(yum install graphviz),木牛问题;

3、接着再试着安装libgraphviz-dev,安装失败;

4、转而使用pip安装,出现如下错误:

Your graphviz installation could not be found.

Either the graphviz package is missing on incomplete
(binary packages graphviz-dev or graphviz-devel missing?).

If you think your installation is correct you will need to manually
change the include_path and library_path variables in setup.py to
point to the correct locations of your graphviz installation.

The current setting of library_path and include_path is:
library_path=None
include_path=None

error: None

使用pip安装和easy_install所不同的是,其在主文件夹中会出现一个bulid文件夹,pygraphviz文件被下载缓存在此;

5、于是,修改pygraphviz文件夹中的setup.py文件夹,我使用的是vi;

在其中可以看到:

from glob import glob

import os

import sys

if os.path.exists('MANIFEST'): os.remove('MANIFEST')

 

from distutils.core import setup, Extension

 

from setup_extra import pkg_config, dotneato_config

 

if sys.argv[-1] == 'setup.py':

    print "To install, run 'python setup.py install'" //这个我们接下来会用到的;

    print

 

if sys.version_info[:2] < (2, 4):

    print "PyGraphviz requires Python version 2.4 or later (%d.%d detected)." % \

          sys.version_info[:2]

    sys.exit(-1)

 

library_path=None

include_path=None

 上面这两行需要注释掉

# If the setup script couldn't find your graphviz installation you can

# specify it here by uncommenting these lines or providing your own:

# You must set both 'library_path' and 'include_path'

 

# Linux, generic UNIX

#library_path='/usr/lib/graphviz'

#include_path='/usr/include/graphviz'

 

# OSX, Linux, alternate location

#library_path='/usr/local/lib/graphviz'

#include_path='/usr/local/include/graphviz'

 上面这两行需要取消注释

# OSX (Fink)

#library_path='/sw/lib/graphviz'

#include_path='/sw/include/graphviz'

 

# OSX (MacPorts)

#library_path='/opt/local/lib/graphviz'

#include_path='/opt/local/include/graphviz'

 

# Windows

# Unknown

 

# Attempt to find Graphviz installation

if library_path is None and include_path is None:

    print "Trying pkg-config"

    include_path,library_path=pkg_config()

 

if library_path is None and include_path is None:

    print "Trying dotneato-config"

    include_path,library_path=dotneato_config()

 

if library_path is None or include_path is None:

    print 

    print  """Your Graphviz installation could not be found.

 

1) You don't have Graphviz installed:

   Install Graphviz (http://graphviz.org)

 

2) Your Graphviz package might incomplete.

   Install the binary development subpackage (e.g. libgraphviz-dev or similar.)

 

3) You are using Windows

   There are no PyGraphviz binary packages for Windows but you might be

   able to build it from this source.  See

   http://networkx.lanl.gov/pygraphviz/reference/faq.html

这个不就是之前的错误提示么? 

If you think your installation is correct you will need to manually

change the include_path and library_path variables in setup.py to

point to the correct locations of your graphviz installation.

6、按照上述操作进行修改,之后运行 python setup.py install,但是依然出现错误:“gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fs………………” 

7、应该是gcc包缺失,于是乎,继续安装gcc;使用yum install gcc,出现错误——一些依赖包无法安装;

8、判断可能是某些包版本不够新,升级之(update-testing)

9、升级完之后,在安装pygraphviz,出现错误:“致命错误,python.h没有这个文件或目录。”

10、然后,安装包“python-dev”(yum install python-devel);

11、easy_install 安装,成功。import pygraphviz,没有报错,OK!

posted on 2012-05-12 21:25  森林之子  阅读(6808)  评论(5编辑  收藏  举报