WSL踩坑之1:安装igraph时,提示yacc: command not found错误解决办法

本文记录了在Win10-WSL-Ubuntu环境下安装igraph库的过程,包括解决yacc未安装及语法错误等问题,并最终通过更新pip版本成功安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境: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成功,问题解决。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值