首页 > 解决方案 > 无法调用 Waf - ImportError:无法导入名称脚本

问题描述

我正在尝试安装 ns-3 网络模拟器,并且正在构建一个简单的脚本,它将在全新安装最新的 Ubuntu LTS OS(18.04) 时安装所有先决条件。

一切都很顺利,但是一旦我尝试运行任何测试,就会出现以下错误:

Traceback (most recent call last):   
 File "./source/ns-3.29/test.py", line 1942, in <module>
   sys.exit(main(sys.argv))   
 File "./source/ns-3.29/test.py", line 1939, in main
   return run_tests()   
 File "./source/ns-3.29/test.py", line 1010, in run_tests
   read_waf_config()   File "./source/ns-3.29/test.py", line 579, in read_waf_config
   for line in open(".lock-waf_" + sys.platform + "_build", "rt"): 
 IOError: [Errno 2] No such file or directory: '.lock-waf_linux2_build'

当我简单地尝试时也会发生这种情况: ./waf --help

脚本没有做任何引人注目的事情,但这里只是以防万一。它必须使用调用sudo

#!/bin/bash
echo "Installing..."

#   basic OS update
apt update
apt upgrade -y
apt dist-upgrade -y
apt autoremove -y
apt autoclean -y

#   install prerequisites
apt install git -y
apt install gcc -y
apt install g++ -y
apt install mercurial -y
apt install cvs -y
apt install bzr -y
apt install make -y
apt install cmake -y
apt install qt5-default -y
apt install qtcreator -y
apt install python-gi-cairo -y
apt install gir1.2-goocanvas-2.0 -y
apt install python-pygraphviz -y
apt install python-dev -y
apt install python-setuptools -y

##  acquire Bake
git clone https://gitlab.com/nsnam/bake

#   add Bake to PATH
export BAKE_HOME=`pwd`/bake 
export PATH=$PATH:$BAKE_HOME
export PYTHONPATH=$PYTHONPATH:$BAKE_HOME

#   check if all valid
bake.py check

#   configure Bake for ns-3
bake.py configure -e ns-3.29
bake.py show

#   download and build ns-3
bake.py download
cd ./source/ns-3.29/ && ./waf configure && cd ../../
bake.py build
#instead of 3 lines above this comment there was previously just "bake.py deploy"

./source/ns-3.29/test.py #this causes an error

echo "Finished Install!"

./waf configure给出以下输出: 输出(pastebin)

标签: pythonns-3waf

解决方案


ns-3 在发行版中捆绑了 waf。当您从头开始构建时,您要做的第一件事就是运行./waf configure,以便将 waf 模块解压缩到一个名为waf3-2.0.15-ff6573b86ad5ff5d449c8852ad58b8bc. 丢失Scripting的应该是文件waf3-2.0.15-ff6573b86ad5ff5d449c8852ad58b8bc/waflib/Scripting.py

我不知道出了什么问题,因为你没有提供足够的线索。但是检查ns3目录中是否有我上面提到的目录,如果有,删除它然后./waf configure再次运行。


推荐阅读