Robotics StackExchange | Archived questions

ModuleNotFoundError: No module named 'netifaces'

Error occurs when I run roscore

I installed python 2.7 manually.

praneeth@praneeth-Lenovo-Legion-Y540-15IRH-PG0:~/catkin_ws/src$ roscore
... logging to /home/praneeth/.ros/log/f4804f00-22ff-11ea-bce8-907841bf4730/roslaunch-praneeth-Lenovo-Legion-Y540-15IRH-PG0-5603.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://praneeth-Lenovo-Legion-Y540-15IRH-PG0:40321/
ros_comm version 1.14.3


PARAMETERS

/rosdistro: melodic
/rosversion: 1.14.3
NODES

Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/init.py", line 322, in main
p.start()
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/parent.py", line 288, in start
self.runner.launch()
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/launch.py", line 662, in launch
self._setup()
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/launch.py", line 637, in _setup
launched = self._launch_master()
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/launch.py", line 400, in _launch_master
validate_master_launch(m, self.is_core, self.is_rostest)
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/launch.py", line 83, in validate_master_launch
if not rosgraph.network.is_local_address(m.get_host()):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosgraph/network.py", line 175, in is_local_address
local_addresses = ['localhost'] + get_local_addresses()
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosgraph/network.py", line 217, in get_local_addresses
import netifaces
ModuleNotFoundError: No module named 'netifaces'

The result of which python: /usr/bin/python echo $PYTHONPATH /opt/ros/melodic/lib/python2.7/dist-packages python2 -c import netifaces: blank line

Asked by planebula on 2020-03-05 04:20:52 UTC

Comments

More information would be helpful. What platform are you running on? If you installed Python 2 manually, did you also rebuild ROS against your Python2 installation? Did you use rosdep to install ROS's dependencies?

Asked by nuclearsandwich on 2020-03-05 10:34:21 UTC

Running it on Ubuntu 18.04. Yes I rebuilt ROS after installing Python 2.7 and used rosdep to install dependencies, including netifaces. It seems roscore isn't able to find 2.7 in its path

Asked by planebula on 2020-03-05 16:23:05 UTC

When I run: rosdep install netifaces I get WARNING: ROS_PYTHON_VERSION is unset. Defaulting to 3 ERROR: Rosdep cannot find all equired resources to answer your query Missing resource netifaces

However, echo $ROS_PYTHON_VERSION returns 2

Asked by planebula on 2020-03-05 16:43:06 UTC

another error i get when running rosdep install netifaces is ERROR: Rosdep cannot find all required resources to answer your query Missing resource netifaces ROS path [0]=/opt/ros/melodic/share/ros ROS path [1]=/opt/ros/melodic/share

Asked by planebula on 2020-03-05 16:50:31 UTC

I hope this gets to be solved soonest as I've been battling this exact bug for about 48hrs now. What I plan to try is to install the module 'netifaces' directly to dist-packages. I'll let you know how it goes.

Asked by Irikefe on 2020-03-06 00:11:46 UTC

@irikefe have you also built your own Python 2? If not it's probably worth opening a second question.

Asked by nuclearsandwich on 2020-03-06 12:59:15 UTC

Running it on Ubuntu 18.04. Yes I rebuilt ROS after installing Python 2.7 and used rosdep to install dependencies, including netifaces. It seems roscore isn't able to find 2.7 in its path

It just occurred to me that if you built your own Python 2.7 that apt packages providing python libraries may not be being used by your python installation. Can you please update your question to include: Your current value of $PYTHONPATH, the result of which python2, and the result of python2 -c 'import netifaces

Asked by nuclearsandwich on 2020-03-06 13:05:49 UTC

another error i get when running rosdep install netifaces is

This is because the rosdep key is named python-netifaces, matching the apt package name rather than the python import name.

Asked by nuclearsandwich on 2020-03-06 13:06:49 UTC

@nuclearsandwich python2 wasn't manually built in my case. From my efforts trying to resolve this, I discovered netifaces isn't installed in /opt/ros/melodic/lib/python2.7/dist-packages/ and manually adding the module files resulted in the error File "/opt/ros/melodic/lib/python2.7/dist-packages/rosgraph/network.py", line 217, in get_local_addresses import netifaces ImportError: /home/user/.local/lib/python2.7/site-packages/netifaces.so: undefined symbol: _Py_ZeroStruct

Asked by Irikefe on 2020-03-06 23:13:42 UTC

Is there a way to discover the exact version of netifaces needed?

Asked by Irikefe on 2020-03-06 23:16:13 UTC

@Irikefe please create your own question instead of commenting on this one. Your problem is different from this poster's and will have a different answer.

Asked by nuclearsandwich on 2020-03-07 00:06:54 UTC

@nuclearsandwich, what @Irikefe is describing seems to be the exact same thing I am experiencing. I think we have an identical setup, probably following the same ROS tutorials.

Asked by planebula on 2020-03-07 00:10:53 UTC

@nuclearsandwich I updated my question to reflect the return values of the commands you requested

Asked by planebula on 2020-03-07 00:19:45 UTC

I'd recommend adding the output of python --version as well.

It could still be roscore is being executed by a Python 3 interpreter. And seeing as all dependencies for ROS Melodic will only be installed for the system provided Python, netifaces could simply not have been installed for any other Python interpreter.

@Irikefe: unless you're trying to use a custom built Python, Python 3 and/or something like Anaconda or other alternative Python interpreters with their own separate dist- and site-packages, there should be no need to fiddle with PYTHONPATH manually or to copy packages/modules/files into any directories yourself.

A standard setup of ROS Melodic on Ubuntu will depend on the system provided Python 2, all dependencies will be installed for that, and all search paths will be setup correctly for that setup.

If you have something else, that's when you need to start making changes.

Asked by gvdhoorn on 2020-03-07 04:49:44 UTC

python2 -c import netifaces: blank line

which tells us that at least for python2 netifaces has been installed correctly.

That Python interpreter is most likely the system provided one.

But: all ROS Melodic Python scripts (or at least: those distributed via repositories.ros.org) will have #!/usr/bin/env python as the hash-bang. They don't have python2 there.

So if you're system has linked python to python3 (or something else), things still won't work, as a Python interpreter different from the one for which everything has been installed will be used to run the scripts.

Asked by gvdhoorn on 2020-03-07 04:52:19 UTC

Answers

So I eventually found a fix to the issue. So after studying ROS filesystem it became apparent that the issue was due to the wrong default interpreter linking. Although python --version returned python2.7 this was only made possible in my case because I used an alias in my .bashrc profile.

To fix this you have to change the default python version using python2.7 alternative. Based on your bug response it is apparent python3 was your default interpreter which was the same in my case.

First list available alternatives update-alternatives --list python. If python2.7 isn't a part of the list and you have it installed, add it to the alternatives using update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

Finally, configure the alternatives using update-alternatives --config python and select python2.7 as the default.

Asked by Irikefe on 2020-03-07 10:55:47 UTC

Comments