环境:Win10-WSL-Ubuntu 18.04 LTS
使用pip安装igraph时
sudo pip install python-igraph
发生如下错误信息:
Building igraph...
make all-recursive
make[1]: Entering directory '/tmp/pip-build-a4u1iH/python-igraph/vendor/build/igraph'
Making all in src
make[2]: Entering directory '/tmp/pip-build-a4u1iH/python-igraph/vendor/build/igraph/src'
YACC foreign-ncol-parser.c
../../../source/igraph/ylwrap: line 176: yacc: command not found
Makefile:9045: recipe for target 'foreign-ncol-parser.c' failed
make[2]: *** [foreign-ncol-parser.c] Error 127
make[2]: Leaving directory '/tmp/pip-build-a4u1iH/python-igraph/vendor/build/igraph/src'
Makefile:497: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/pip-build-a4u1iH/python-igraph/vendor/build/igraph'
Makefile:404: recipe for target 'all' failed
make: *** [all] Error 2
Could not compile the C core of igraph.
按照提示判断为yacc未安装。
按照百度到的信息:yacc(Yet Another Compiler Compiler),是一个经典的生成语法分析器的工具。yacc生成的编译器主要是用C语言写成的语法解析器(Parser),需要与词法解析器Lex一起使用,再把两部份产生出来的C程序一并编译。
安装yacc:
sudo apt-get install -y byacc
安装成功后再安装igraph:
sudo pip install python-igraph
出现错误:
Building igraph...
make all-recursive
make[1]: Entering directory '/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph'
Making all in src
make[2]: Entering directory '/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph/src'
YACC foreign-ncol-parser.c
byacc: e - line 74 of "/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph/src/../../../source/igraph/src/foreign-ncol-parser.y", syntax error
%output="y.tab.c"
^
Makefile:9045: recipe for target 'foreign-ncol-parser.c' failed
make[2]: *** [foreign-ncol-parser.c] Error 1
make[2]: Leaving directory '/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph/src'
Makefile:497: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph'
Makefile:404: recipe for target 'all' failed
make: *** [all] Error 2
Could not compile the C core of igraph.
出错位置为:
byacc: e - line 74 of "/tmp/pip-build-8_t2M7/python-igraph/vendor/build/igraph/src/../../../source/igraph/src/foreign-ncol-parser.y", syntax error
%output="y.tab.c"
^
错误形式为:“syntax error”,猜想可能为pip版本太老。尝试更新pip版本:
sudo python -m pip install --upgrade --force pip
安装成功后返回信息,可见从pip 9升级到了pip 20:
Installing collected packages: pip
Found existing installation: pip 9.0.1
Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-20.3.1
更新pip成功后再安装:
sudo pip install python-igraph
出现
Requirement already satisfied: texttable>=1.6.2 in /usr/local/lib/python2.7/dist-packages (from python-igraph) (1.6.3)
Installing collected packages: python-igraph
Successfully installed python-igraph-0.8.3
至此,安装igraph成功,问题解决。