Python bindings

597 views
Skip to first unread message

Ali A. Salehpour

unread,
Jul 4, 2023, 4:13:20 PM7/4/23
to ns-3-users
Hello, 

I am using Ubuntu 22.04 on WSL 2 to install ns-3. 
I downloaded and install ns-3.38 by ./ns3 tool. However, the Python bindings is "OFF" and I couldn't to enable it. I Want to use Python to run ns-3 programs, thus, I need Python bindings. 
How can I enable it?


Tom Henderson

unread,
Jul 4, 2023, 4:58:04 PM7/4/23
to ns-3-...@googlegroups.com
You need to have Python cppyy installed, no later than version 2.4.2.  You can check the version like this:

  $ python3
  Python 3.8.10 (default, Jun 22 2022, 20:18:18)
  [GCC 9.4.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import cppyy
  >>> print("%s" % cppyy.__version)
  2.4.2
  >>>

To install this specific version, you can use pip like this:

  $ python3 -m pip install cppyy==2.4.2

Then, to enable Python bindings, you add the following to the configure step:

  $ ./ns3 configure --enable-python-bindings
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/474b7779-4e6b-4ff3-b312-9d0102fef804n%40googlegroups.com.


Ali A. Salehpour

unread,
Jul 5, 2023, 4:42:00 PM7/5/23
to ns-3-users
Thank you very much, Tom.
I worked properly. But, when I closed the terminal and ran "first.py" again, I faced the same error (no module named 'ns').
I ran the following command and it was fixed.

$ pip install ns3

Tom Henderson

unread,
Jul 5, 2023, 4:46:19 PM7/5/23
to ns-3-...@googlegroups.com, Ali A. Salehpour
Keep in mind that what you did the second time did a very different
thing-- it installed the ns-3 libraries from pip. The first command
used the ns-3 libraries built locally.

Now, you may have two installations of ns-3 libraries on your system,
and depending on how your Python environment (path) is set up, one will
take precedence the next time that you call 'import ns3'.
>> https://groups.google.com/d/msgid/ns-3-users/474b7779-4e6b-4ff3-b312-9d0102fef804n%40googlegroups.com <https://groups.google.com/d/msgid/ns-3-users/474b7779-4e6b-4ff3-b312-9d0102fef804n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
> --
> Posting to this group should follow these guidelines
> https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
> <https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting>
> ---
> You received this message because you are subscribed to the Google
> Groups "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ns-3-users+...@googlegroups.com
> <mailto:ns-3-users+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ns-3-users/f4307760-4859-4eb4-9e29-2a87a4d1e154n%40googlegroups.com <https://groups.google.com/d/msgid/ns-3-users/f4307760-4859-4eb4-9e29-2a87a4d1e154n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages