3

I'm using Python virtualenv and I'm having a problem with a module (installed inside the virtualenv).

First of all, I activate the virtualenv:

source path_to_virtualenv/bin/activate

The virtualenv is correctly activated (its name appears in the shell). Inside that virtualenv, I installed mininet (a network simulator): I'm sure it is correctly installed (it is listed by the command pip list).

However, when I try to run my application, I obtain the following error over a module of Mininet API:

from mininet.net import Mininet ImportError: No module named net

How is it possible? Using an IDE, it correctly detects all Mininet's modules (in the same virtualenv); does someone have some ideas?

Thanks

Gabriele
  • 31
  • 3

1 Answers1

0

Check to see if your project is in the same directory as your virtual environment.

If not start your virtual env. in the the command prompt and then cd to the project.

hope that helps a little

Kyle Andersen
  • 81
  • 1
  • 9
  • Thank for your reply. Project and virtualenv are not in the same directory; I directly activated the virtualenv inside the project's folder; I suppose virtualenv is correctly activated because running the command `which python` I get `/opt/sdn/mininet/2.1.0/bin/python` that is inside the virtualenv's folder...thanks again. – Gabriele Jul 21 '15 at 13:14
  • Moreover, if I open a python interpreter inside the virutalenv and I try to import that module, I have no errors: `(sdn)~$ python >>>from mininet.net import Mininet >>>` It's completely unclear what's happening... – Gabriele Jul 21 '15 at 13:26
  • that is interesting. so you have no problems from inside the interpreter then? – Kyle Andersen Jul 21 '15 at 13:31
  • Exactly. That error is not raised inside the interpreter. – Gabriele Jul 21 '15 at 20:24
  • 3
    Ok, I solved my problem. This was stupidly due to the fact that I named the file in which I imported mininet.net.* in the same way of the mininet module, namely mininet.py in my application. Reading the python doc about the modules ([link](https://docs.python.org/2/tutorial/modules.html#the-module-search-path) )I understood that the application was looking for mininet.net inside my mininet module (mininet.py) and not in mininet/net.py module. I just renamed my mininet.py file and I solved the problem. – Gabriele Jul 22 '15 at 15:44