module not found by python

3,818 views
Skip to first unread message

H. Rahimi

unread,
Sep 18, 2011, 7:51:11 AM9/18/11
to ns-3-users
I have followed the tutorial fully and using hg and the all in one
package I have downloaded and built ns3, but when I run an example I
get an exception:

Command:

hossein@hossein-ThinkPad-T420s ~/workspace/ns-3-allinone/ns-3-dev $ ./
waf --pyrun examples/wireless/wifi-ap.py

Output:

Waf: Entering directory `/home/hossein/workspace/ns-3-allinone/ns-3-
dev/build'
Waf: Leaving directory `/home/hossein/workspace/ns-3-allinone/ns-3-dev/
build'
'build' finished successfully (1.244s)
Traceback (most recent call last):
File "examples/wireless/wifi-ap.py", line 25, in <module>
import ns.applications
ImportError: No module named applications
Command ['/usr/bin/python', 'examples/wireless/wifi-ap.py'] exited
with code 1


How should I act to install the modules correctly? should I copy some
files to dist-packages manually?

Thanks

sanjeev prasad

unread,
Sep 19, 2011, 3:58:57 AM9/19/11
to ns-3-...@googlegroups.com
you have to install python APIs using synaptic. if you r using ubuntu. 


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Sanjeev K. Prasad
Assistant Professor 
MCA Dept.
AKGEC, GZB
Mob. 09711117484

Hossein Rahimi

unread,
Sep 19, 2011, 1:44:31 PM9/19/11
to ns-3-...@googlegroups.com
You know that using apt there is a module pyton-ns3 that could be installed. This module has no hierarchical structure! The module used in python examples is completely different!

The examples are like this:
import ns.applications
import ns.network
....

While if you install it from apt repos, you'll have to do like the following:

import ns3
container = ns3.NodeContainer(2)


Why!???

Where are this modules' files and how can I install them?
I am wondering has anyone written ns3 simulation scripts in python, except the project developers?

That will be great to build a better community of python geeks for the py part of the job...

Cheers,

Gustavo Carneiro

unread,
Sep 19, 2011, 2:20:00 PM9/19/11
to ns-3-...@googlegroups.com
On Mon, Sep 19, 2011 at 18:44, Hossein Rahimi <hossein...@gmail.com> wrote:
You know that using apt there is a module pyton-ns3 that could be installed. This module has no hierarchical structure! The module used in python examples is completely different!

The examples are like this:
import ns.applications
import ns.network
....

While if you install it from apt repos, you'll have to do like the following:

import ns3
container = ns3.NodeContainer(2)


Why!???


At least in my Ubuntu 11.04, the ns-3 package is still at version ns-3.9, but the latest ns-3 is 3.12.1.

The ns-3 Python bindings have changed in ns 3.11.  They have now become modular.  The monolithic bindings only consist of a single 'ns3' module, which binds everything.  The modular bindings are 'ns' package with many Python modules inside, one for each ns-3 module: ns.core, ns.network, ns.applications, etc.

The ns-3 bindings changed like this:

- ns <= 3.10: only the old monolithic bindings available;

- ns 3.11: both monolithic and modular bindings are available;

- ns >= 3.12: monolithic bindings are gone, only modular ones are available.  But there is a compatibility layer module generated, ns3.py, to keep older scripts working with a deprecation warning[1].

[1] Unfortunately deprecation warnings are disabled by default since Python 2.7 :(



--
Gustavo J. A. M. Carneiro
INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
"The universe is always one step beyond logic." -- Frank Herbert

Hossein Rahimi

unread,
Sep 19, 2011, 2:41:13 PM9/19/11
to ns-3-...@googlegroups.com
So, if I have the clone of the development repository... How can I tell it to install the hierarchical modules to Python's dist-package?
Because it is a bit painful to program with the older ns3 module.

Gustavo Carneiro

unread,
Sep 19, 2011, 2:47:53 PM9/19/11
to ns-3-...@googlegroups.com
On Mon, Sep 19, 2011 at 19:41, Hossein Rahimi <hossein...@gmail.com> wrote:
So, if I have the clone of the development repository... How can I tell it to install the hierarchical modules to Python's dist-package?
Because it is a bit painful to program with the older ns3 module.

The development repo is not stable.  Try ns-3.12.1 and the command ./waf install.

Hossein Rahimi

unread,
Sep 19, 2011, 3:14:33 PM9/19/11
to ns-3-...@googlegroups.com
Okay, I tried the 3.12.1 tarball and the same result:

  • configure:
./waf -d debug --enable-examples --enable-tests --enable-sudo configure --enable-mpi

output:
---- Summary of optional NS-3 features:
Static build                  : not enabled (option --enable-static not selected)
Threading Primitives          : enabled
Real Time Simulator           : enabled
Emulated Net Device           : enabled
Tap Bridge                    : enabled
GtkConfigStore                : not enabled (library 'gtk+-2.0 >= 2.12' not found)
XmlIo                         : enabled
Network Simulation Cradle     : not enabled (NSC library liblinux2.6.26.so is missing: NSC has not been built?)
NS-3 Click Integration        : not enabled (nsclick not enabled (see option --with-nsclick))
NS-3 OpenFlow Integration     : not enabled (OpenFlow not enabled (see option --with-openflow))
SQlite stats data output      : not enabled (library 'sqlite3' not found)
Python Bindings               : enabled
Python API Scanning Support   : enabled
MPI Support                   : enabled
Use sudo to set suid bit      : enabled
Build tests                   : enabled
Build examples                : enabled
GNU Scientific Library (GSL)  : enabled
'configure' finished successfully (3.693s)

  • build:
./waf -j8 build

end of output:
build' finished successfully (5m40.770s)

Modules built:
aodv                      applications              bridge                  
config-store              core                      csma                    
csma-layout               dsdv                      emu                     
energy                    flow-monitor              internet                
lte                       mesh                      mobility                
mpi                       netanim                   network                 
nix-vector-routing        ns3tcp                    ns3wifi                 
olsr                      point-to-point            point-to-point-layout   
propagation               spectrum                  stats                   
tap-bridge                template                  test                    
tools                     topology-read             uan                     
virtual-net-device        visualizer                wifi                    
wimax                   

Modules not built:
click                     openflow                


  • installation:

sudo ./waf install

end of output:

Waf: Leaving directory `/home/hossein/Downloads/ns-allinone-3.12.1/ns-3.12.1/build'
'install' finished successfully (2.394s)

Modules built:
aodv                      applications              bridge                  
config-store              core                      csma                    
csma-layout               dsdv                      emu                     
energy                    flow-monitor              internet                
lte                       mesh                      mobility                
mpi                       netanim                   network                 
nix-vector-routing        ns3tcp                    ns3wifi                 
olsr                      point-to-point            point-to-point-layout   
propagation               spectrum                  stats                   
tap-bridge                template                  test                    
tools                     topology-read             uan                     
virtual-net-device        visualizer                wifi                    
wimax                   

Modules not built:
click                     openflow                


But still we fail on ns modules:
command:
./waf --pyrun examples/tutorial/first.py

output:
Waf: Entering directory `/home/hossein/Downloads/ns-allinone-3.12.1/ns-3.12.1/build'
Waf: Leaving directory `/home/hossein/Downloads/ns-allinone-3.12.1/ns-3.12.1/build'
'build' finished successfully (1.102s)

Traceback (most recent call last):
  File "examples/tutorial/first.py", line 16, in <module>

    import ns.applications
ImportError: No module named applications


Why doesn't waf install the modules?
Thanks,

Hossein Rahimi

unread,
Sep 19, 2011, 3:54:25 PM9/19/11
to ns-3-...@googlegroups.com
is there any way to manually generate the module directories and then copy them to dist-packages by hand?

Hossein Rahimi

unread,
Sep 20, 2011, 11:51:52 AM9/20/11
to ns-3-...@googlegroups.com
No one to help people? :D
Who I should contact directly about the python part of ns3?

Mitch Watrous

unread,
Sep 20, 2011, 12:12:07 PM9/20/11
to ns-3-users
The following section from the ns-3 module tells you how to create a
module:

www.nsnam.org/docs/release/3.12/manual/html/new-modules.html

The process by which releases are created is discussed here:

ns-3-dev/doc/release_steps.txt

The script that creates the distributions can be found here:

ns-3-allinone/dist.py

The distribution script (dist.py) might include the new module
automatically, or you might need to edit it to include your new
module.

Mitch

On Sep 20, 8:51 am, Hossein Rahimi <hossein.rahe...@gmail.com> wrote:
> No one to help people? :D
> Who I should contact directly about the python part of ns3?
>
> On Mon, Sep 19, 2011 at 4:54 PM, Hossein Rahimi
> <hossein.rahe...@gmail.com>wrote:
>
> > is there any way to manually generate the module directories and then copy
> > them to dist-packages by hand?
>
> > On Mon, Sep 19, 2011 at 4:14 PM, Hossein Rahimi <hossein.rahe...@gmail.com
> > > wrote:
>
> >> Okay, I tried the 3.12.1 tarball and the same result:
>
> >>    - configure:
> >>    - build:
> >>    - installation:
> >> On Mon, Sep 19, 2011 at 3:47 PM, Gustavo Carneiro <gjcarne...@gmail.com>wrote:
>
> >>> On Mon, Sep 19, 2011 at 19:41, Hossein Rahimi <hossein.rahe...@gmail.com
> >>> > wrote:
>
> >>>> So, if I have the clone of the development repository... How can I tell
> >>>> it to install the hierarchical modules to Python's dist-package?
> >>>> Because it is a bit painful to program with the older ns3 module.
>
> >>> The development repo is not stable.  Try ns-3.12.1 and the command ./waf
> >>> install.
>
> >>>> On Mon, Sep 19, 2011 at 3:20 PM, Gustavo Carneiro <gjcarne...@gmail.com
> >>>>> INESC Porto, UTM, WiN,http://win.inescporto.pt/gjc
> >>>>> "The universe is always one step beyond logic." -- Frank Herbert
>
> >>>>> --
> >>>>> You received this message because you are subscribed to the Google
> >>>>> Groups "ns-3-users" group.
> >>>>> To post to this group, send email to ns-3-...@googlegroups.com.
> >>>>> To unsubscribe from this group, send email to
> >>>>> ns-3-users+...@googlegroups.com.
> >>>>> For more options, visit this group at
> >>>>>http://groups.google.com/group/ns-3-users?hl=en.
>
> ...
>
> read more »

Hossein Rahimi

unread,
Sep 20, 2011, 12:15:20 PM9/20/11
to ns-3-...@googlegroups.com
I am not about creating a new module, the ns3 build process should build the modules included by default and in their examples and put it into a right place, when I say ./waf install, and also I have already enabled the --enable-examples!

So, ns3 cannot run its own python examples? What a mess! It is a bug! nothing more....

Gustavo Carneiro

unread,
Sep 20, 2011, 12:16:52 PM9/20/11
to ns-3-...@googlegroups.com
On Tue, Sep 20, 2011 at 16:51, Hossein Rahimi <hossein...@gmail.com> wrote:
No one to help people? :D
Who I should contact directly about the python part of ns3?


That would be me :P

The command "./waf --pyrun examples/tutorial/first.py" runs a python script with _uninstalled_ python bindings and uninstalled ns-3.  But it needs them to have been _built_ before.

I have no idea why it does not work for your case.  We'd have investigate; what files does the directory build/debug/bindings/python/ns contain?

Then try these commands:

./waf shell
python -v examples/tutorial/first.py -c "import ns.applications"

Hossein Rahimi

unread,
Sep 20, 2011, 12:24:36 PM9/20/11
to ns-3-...@googlegroups.com
here is the result:

 installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.7/site.pyc matches /usr/lib/python2.7/site.py
import site # precompiled from /usr/lib/python2.7/site.pyc
# /usr/lib/python2.7/os.pyc matches /usr/lib/python2.7/os.py
import os # precompiled from /usr/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.7/posixpath.pyc matches /usr/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib/python2.7/posixpath.pyc
# /usr/lib/python2.7/stat.pyc matches /usr/lib/python2.7/stat.py
import stat # precompiled from /usr/lib/python2.7/stat.pyc
# /usr/lib/python2.7/genericpath.pyc matches /usr/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib/python2.7/genericpath.pyc
# /usr/lib/python2.7/warnings.pyc matches /usr/lib/python2.7/warnings.py
import warnings # precompiled from /usr/lib/python2.7/warnings.pyc
# /usr/lib/python2.7/linecache.pyc matches /usr/lib/python2.7/linecache.py
import linecache # precompiled from /usr/lib/python2.7/linecache.pyc
# /usr/lib/python2.7/types.pyc matches /usr/lib/python2.7/types.py
import types # precompiled from /usr/lib/python2.7/types.pyc
# /usr/lib/python2.7/UserDict.pyc matches /usr/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib/python2.7/UserDict.pyc
# /usr/lib/python2.7/_abcoll.pyc matches /usr/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib/python2.7/_abcoll.pyc
# /usr/lib/python2.7/abc.pyc matches /usr/lib/python2.7/abc.py
import abc # precompiled from /usr/lib/python2.7/abc.pyc
# /usr/lib/python2.7/_weakrefset.pyc matches /usr/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib/python2.7/copy_reg.pyc matches /usr/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.7/copy_reg.pyc
# /usr/lib/python2.7/traceback.pyc matches /usr/lib/python2.7/traceback.py
import traceback # precompiled from /usr/lib/python2.7/traceback.pyc
# /usr/lib/python2.7/sysconfig.pyc matches /usr/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib/python2.7/sysconfig.pyc
# /usr/lib/python2.7/re.pyc matches /usr/lib/python2.7/re.py
import re # precompiled from /usr/lib/python2.7/re.pyc
# /usr/lib/python2.7/sre_compile.pyc matches /usr/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.7/sre_parse.pyc matches /usr/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.7/sre_parse.pyc
# /usr/lib/python2.7/sre_constants.pyc matches /usr/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.7/sre_constants.pyc
# /usr/lib/python2.7/sitecustomize.pyc matches /usr/lib/python2.7/sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.7/sitecustomize.pyc
import encodings # directory /usr/lib/python2.7/encodings
# /usr/lib/python2.7/encodings/__init__.pyc matches /usr/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.7/encodings/__init__.pyc
# /usr/lib/python2.7/codecs.pyc matches /usr/lib/python2.7/codecs.py
import codecs # precompiled from /usr/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.7/encodings/aliases.pyc matches /usr/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.7/encodings/aliases.pyc
# /usr/lib/python2.7/encodings/utf_8.pyc matches /usr/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.7/encodings/utf_8.pyc
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
# /usr/local/lib/python2.7/dist-packages/ns-0.1-py2.7.egg/ns.pyc matches /usr/local/lib/python2.7/dist-packages/ns-0.1-py2.7.egg/ns.py
import ns # precompiled from /usr/local/lib/python2.7/dist-packages/ns-0.1-py2.7.egg/ns.pyc
import imp # builtin
# /usr/lib/python2.7/pkgutil.pyc matches /usr/lib/python2.7/pkgutil.py
import pkgutil # precompiled from /usr/lib/python2.7/pkgutil.pyc

Traceback (most recent call last):
  File "examples/tutorial/first.py", line 16, in <module>
    import ns.applications
ImportError: No module named applications
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] encodings
# cleanup[1] site
# cleanup[1] sysconfig
# cleanup[1] abc
# cleanup[1] _weakrefset
# cleanup[1] sre_constants
# cleanup[1] re
# cleanup[1] lazr
# cleanup[1] ns
# cleanup[1] _warnings
# cleanup[1] encodings.utf_8
# cleanup[1] codecs
# cleanup[1] pkgutil
# cleanup[1] sitecustomize
# cleanup[1] signal
# cleanup[1] traceback
# cleanup[1] _codecs
# cleanup[1] posix
# cleanup[1] encodings.aliases
# cleanup[1] exceptions
# cleanup[1] _weakref
# cleanup[1] sre_compile
# cleanup[1] _sre
# cleanup[1] zipimport
# cleanup[1] imp
# cleanup[1] sre_parse
# cleanup[2] copy_reg
# cleanup[2] posixpath
# cleanup[2] errno
# cleanup[2] _abcoll
# cleanup[2] types
# cleanup[2] genericpath
# cleanup[2] stat
# cleanup[2] warnings
# cleanup[2] UserDict
# cleanup[2] os.path
# cleanup[2] linecache
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 20 unfreed ints
# cleanup floats

Hossein Rahimi

unread,
Sep 20, 2011, 12:32:05 PM9/20/11
to ns-3-...@googlegroups.com
being in build/debug/bindings:

ls -r */*

output:

python/ns3.py

python/ns:
wimax.so       uan.so            tap_bridge.so  propagation.so            olsr.so                netanim.so   mesh.so      __init__.py      emu.so   _core.so         bridge.so
wifi.so        topology_read.so  stats.so       point_to_point.so         nix_vector_routing.so  mpi.so       lte.so       flow_monitor.so  dsdv.so  core.py          applications.so
visualizer.so  tools.so          spectrum.so    point_to_point_layout.so  network.so             mobility.so  internet.so  energy.so        csma.so  config_store.so  aodv.so

Gustavo Carneiro

unread,
Sep 20, 2011, 1:07:00 PM9/20/11
to ns-3-...@googlegroups.com
From the above lines, it looks like you have some ns-3 python bindings installed in /usr/local, and they are taking precedence.  Try to remove them first.  Also, could you print PYTHONPATH from inside waf shell to make sure it is set correctly?

./waf shell
echo $PYTHONPATH


Hossein Rahimi

unread,
Sep 20, 2011, 3:05:01 PM9/20/11
to ns-3-...@googlegroups.com
removed the /usr/local/lib/python2.7/dist-packages/ns-0.1-py2.7.egg/ns.py....

And it is now working, Thanks a lot :)

--

Hossein Rahimi

unread,
Sep 20, 2011, 3:07:05 PM9/20/11
to ns-3-...@googlegroups.com
Just, I was wondering why don't you submit the up-to-date (for each release) ns3 module to PyPi so people can use that without pain? :D

Vedran Miletić

unread,
Sep 20, 2011, 3:17:22 PM9/20/11
to ns-3-...@googlegroups.com
2011/9/20 Hossein Rahimi <hossein...@gmail.com>

Just, I was wondering why don't you submit the up-to-date (for each release) ns3 module to PyPi so people can use that without pain? :D

I don't believe we should, because they would be tied to specific ns-3 version. It's better to maintain distribution packages. If you are using Ubuntu or Debian, you can already install ns-3 from repository, package name is ns3 (it's maintained by YunQiang Su; see http://packages.debian.org/search?keywords=ns3). Fedora will also have packages available at some point, see http://fedoraproject.org/wiki/Features/Ns3

Vedran

Hossein Rahimi

unread,
Sep 20, 2011, 3:19:39 PM9/20/11
to ns-3-...@googlegroups.com
But the repo version is pretty old...

Hossein
--

Vedran Miletić

unread,
Sep 20, 2011, 3:24:31 PM9/20/11
to ns-3-...@googlegroups.com
2011/9/20 Hossein Rahimi <hossein...@gmail.com>

But the repo version is pretty old...

Hossein

Indeed, but perhaps you can manually install 3.11 from Ubuntu 11.10 repository.

Vedran

Hossein Rahimi

unread,
Sep 20, 2011, 3:36:21 PM9/20/11
to ns-3-...@googlegroups.com
That causes crazy dependency issues, I do not have enough nerve capacity and time to deal with those issues at time... unfortunately...

2011/9/20 Vedran Miletić <riv...@gmail.com>

--

Vedran Miletić

unread,
Sep 20, 2011, 3:41:14 PM9/20/11
to ns-3-...@googlegroups.com
2011/9/20 Hossein Rahimi <hossein...@gmail.com>

That causes crazy dependency issues, I do not have enough nerve capacity and time to deal with those issues at time... unfortunately...

Well, then perhaps someone interested from ns-3 community (you :-) ) can start a PPA with new ns-3 packaged for old versions. Luckily, most of the time spec files don't need to be changed, just a recompile works.

Vedran

Hossein Rahimi

unread,
Sep 20, 2011, 3:44:01 PM9/20/11
to ns-3-...@googlegroups.com
Another crazy issue with the package python-ns3 version 3.12.1 on the repo is that it depends on python 2.6.* :D LoL :D

I am considering doing so :-)

But before that I have to make sure that my urgent net simulation with python works or not :)

2011/9/20 Vedran Miletić <riv...@gmail.com>

--

PURNENDU PANDEY

unread,
Aug 8, 2013, 4:32:33 AM8/8/13
to ns-3-...@googlegroups.com
Please help me....while running an example and it showed :



Traceback (most recent call last):
  File "examples/wireless/wifi-ap.py"
, line 25, in <module>
    import ns.applications
ImportError: No module named applications


Please any one help me, how to remove this problem.




Lester 宋梦凯

unread,
Apr 4, 2016, 6:10:16 AM4/4/16
to ns-3-users
hey I have exactly the same question as you 

as I read your discuss ,I try the command below

./waf shell
python -v examples/tutorial/first.py -c "import ns.applications"

and I get the same output as you

question is ,/usr/local/lib/python2.7/dist-packages/ns-0.1-py2.7.egg/ns.py...   I cannot find this file, /usr/local/lib/python2.7/dist-packages/ is empty 

I'm new in ns3 ,new in this group ,pls help me ,thanks :)





在 2011年9月21日星期三 UTC+8上午12:24:36,H. Rahimi写道:

Tommaso Pecorella

unread,
Apr 4, 2016, 6:41:35 AM4/4/16
to ns-3-users
Hi,

pelase take your time to read the tutorial and the posting guidelines (you're replying to a 5-years old thread).
Make sure to be using the very latest ns-3 release (it's 3.25 at the moment of writing) and that you do have Python configured correctly, i.e., PyBindGen, etc. The ns-3 configuration process should tell you if Python integration is enabled or not.
In case you have further doubts, feel free to ask... with all the relevant details (it's explained in the posting guidelines).

Thanks,

T.
Reply all
Reply to author
Forward
0 new messages