# $PYTHONPATH is not in sync with Python sys.path I have build ROS Melodic on a Raspberry Pi using the supplied instructions. This seems to work fine and I'm able to build my own workspace. However, after sourcing setup.bash, the$PYTHONPATH variable is not in line with what Python reports as its path. Thus certain libraries can not be found when executing ROS programs (eg std_msgs needs PyYAML, which is installed, but not available when running the project through roslaunch)

Is this a misconfiguration on my end? What can I verify and change to make this work?

pi@raspberrypi:~ $echo$PYTHONPATH
/home/pi/ros-robot-control/HelloWorld/robot_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages
pi@raspberrypi:~ $python Python 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print(sys.path) ['', '/home/pi/ros-robot-control/HelloWorld/robot_ws/devel/lib/python2.7/dist-packages', '/opt/ros/melodic/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-arm-linux-gnueabihf', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/pi/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk3']  The error when using roslaunch: Traceback (most recent call last): File "/home/pi/ros-robot-control/HelloWorld/robot_ws/src/ros_robot_control/scripts/cmd_vel_listener.py", line 2, in <module> import rospy File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 47, in <module> from std_msgs.msg import Header File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/__init__.py", line 1, in <module> from ._Bool import * File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/_Bool.py", line 5, in <module> import genpy File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/__init__.py", line 34, in <module> from . message import Message, SerializationError, DeserializationError, MessageException, struct_I File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py", line 47, in <module> import yaml ModuleNotFoundError: No module named 'yaml'  pyyaml is installed, but not in any of the folders in$PYTHONPATH:

pi@raspberrypi:~/ros-robot-control/HelloWorld/robot_ws/src/robot_interface $pip install pyyaml Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: pyyaml in /usr/lib/python2.7/dist-packages (3.13)  edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted In the mean time, I figured it out. The$PYTHONPATH was a red herring and not related to the problem.

The code was indeed calling an incorrectly configured Python binary, but this was not due to the \$PYTHONPATH.

The file cmd_vel_listener.py had an incorrect shebang. After changing it to the default everything works:

#!/usr/bin/env python

more