在目录/opt/ns-allinone-2.35/ns-2.35/tcl/ex下键入ns simpe.tcl,运行发生错误,提示如下:
[root@localhost ex]# ns simple.tcl
210
0.0037499999999999999
running nam...
[root@localhost ex]# nam: Can't find a usable tk.tcl in the following directories:
/opt/ns-allinone-2.35/tcl8.5.10/library/tk8.5 /opt/ns-allinone-2.35/tcl8.5.10/tk8.5 ./lib/tk8.5 /opt/ns-allinone-2.35/lib/tk8.5 ./library
/opt/ns-allinone-2.35/lib/tk8.5/tk.tcl: wrong # args: should be "::source fileName"
wrong # args: should be "::source fileName"
while executing
"::source -encoding utf-8 /opt/ns-allinone-2.35/lib/tk8.5/msgs/en.msg"
("uplevel" body line 1)
invoked from within
"uplevel 1 [list ::source -encoding utf-8 $langfile]"
(procedure "::msgcat::mcload" line 10)
invoked from within
"::msgcat::mcload [file join $::tk_library msgs]"
(in namespace eval "::tk::msgcat" script line 23)
invoked from within
"namespace eval msgcat {
namespace export mc mcmax
if {[interp issafe] || [catch {package require msgcat}]} {
# The msgcat package..."
(in namespace eval "::tk" script line 3)
invoked from within
"namespace eval ::tk {
# Set up the msgcat commands
namespace eval msgcat {
namespace export mc mcmax
if {[interp issafe] || [catch {p..."
(file "/opt/ns-allinone-2.35/lib/tk8.5/tk.tcl" line 21)
invoked from within
"source.orig /opt/ns-allinone-2.35/lib/tk8.5/tk.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig [list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
(procedure "source" line 8)
invoked from within
"source /opt/ns-allinone-2.35/lib/tk8.5/tk.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $file]"
This probably means that tk wasn't installed properly.
因为提示内容太多,我只看了前面几行和后面几行。前面的提示是说:不能找到可用的tk.tcl,寻找路径为:
/opt/ns-allinone-2.35/tcl8.5.10/library/tk8.5 /opt/ns-allinone-2.35/tcl8.5.10/tk8.5 ./lib/tk8.5 /opt/ns-allinone-2.35/lib/tk8.5 ./library
最后一行的提示是:可能是因为tk类的开发包没有被安装。
在之前的印象中,好像也没有安装tk类的开发包,于是就在命令行中输入了如下安装命令:
[root@localhost ~]# yum install tk-devel
[root@localhost ~]# yum install tkinter
待安装完成后,在/opt/ns-allinone-2.35/ns-2.35/tcl/ex目录下重新运行一下“ns simple.tcl”,结果还是同样的错误。
而后又看了看错误提示前面的内容,“找不到可用的tk.tcl”,这使我想起.bashrc文件,是不是环境变量的配置的问题呐?打开.bashrc,显示内容如下:
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PATH=$PATH:/opt/ns-allinone-2.35/bin:/opt/ns-allinone-2.35/tcl8.5.10/uinx:/opt/ns-allinone-2.35/tk8.5.10/unix
export LD_LIBRARY_PATH=/opt/ns-allinone-2.35/otcl-1.14,/opt/ns-allinone-2.35/lib
export TCL_LIBRARY=/opt/ns-allinone-2.35/tcl8.5.10/library
最后三行是安装完NS2后配置的,把最后一行改成如下形式:
export TCL_LIBRARY=$TCL_LIBRARY:/opt/ns-allinone-2.35/tcl8.5.10/library
然后再在命令行里输入:
source ./bashrc //此时命令的输入是在~目录下;
现在就可以在在/opt/ns-allinone-2.35/ns-2.35/tcl/ex目录下运行
ns simple.tcl
运行结果正常。
因为是刚接触Linux和ns2,到现在还不知道.bashrc中的export代表什么意思和source命令的作用,在安装NS的过程中出现过很多问题,上述只是其中的一个问题,希望能给刚接触ns2的朋友一点帮助。