Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named netifaces

I'm trying to get the IP address and MAC address of my pc's network card by python. I got some code from here

I create a proj "getip". create "main.py". And I modify the code of "main.py" as follow

from netifaces import interfaces, ifaddresses, AF_INET

def ip4_addresses():
    ip_list = []
    for interface in interfaces():
        for link in ifaddresses(interface)[AF_INET]:
            ip_list.append(link['addr'])

    return ip_list

def main():
    print ip4_addresses()


if __name__ == "__main__":
    main()

and I create "app.yaml"

application: getip
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py

and when I run the main.py at console as "python main.py", I got the ip addresses.

and when I run as "dev_appserver.py getip", the server is setup. When I browse the page as localhost:8080, the web page is white screen and I got the following error at console.

from netifaces import interfaces, ifaddresses, AF_INET

ImportError: No module named netifaces

How can I solve the problem?

like image 881
Thu Ra Avatar asked Oct 12 '13 09:10

Thu Ra


1 Answers

just install netifaces

pip install netifaces if you have pip installed, or download the source, unpack it run and python setup.py install

warning: this will install it globally on your system, so use caution, or use virtualenv

like image 150
mislavcimpersak Avatar answered Sep 25 '22 01:09

mislavcimpersak