我的pygraphviz安裝之路


近來,在學習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!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM