ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS Melodic no longer finding python scripts

asked 2022-08-01 14:06:05 -0500

vbplaya gravatar image

NOTE: Working in Windows (I have to because this is the machine that my work requires me to use).

I’m creating a project which will communicate with another companies ROS project. Originally, I was building it in Noetic (which was also on this same windows machine) but I was told they are using Melodic so I have to revert back to Melodic on mine. When I was running my packages in Noetic it ran fine … I used the following command:

rosrun gui_pkg main.py

However, when I changed over to Melodic for some reason it no longer can find the main.py so in order to run it, I need to run the following command:

rosrun gui_pkg scripts/main.py

That’s not a big deal but I am now running into errors finding other custom libraries. For example, the following import no longer works:

from gui_templates.tx_rx_display import TxRxDisplay

Any ideas of why this is now an issue? Btw, I also have the very simple talker.py/listener.py package from the ROS website that worked completely fine in Noetic but requires the "scripts/talker.py" in the rosrun command in order to run as well.

Some relevant info:

OS: Windows 10

folder layout under gui_pkg folder

  • setup.py
  • CMakeLists.txt
  • package.xml
  • scripts
    • main.py
    • gui_templates
      • tx_rx_display.py

CONTENTS of setup.py:

 from distutils.core import setup
 from catkin_pkg.python_setup import generate_distutils_setup

 d = generate_distutils_setup(
     packages=[‘gui_templates’],
     package_dir={‘’: ‘scripts’}
 )
 setup(**d)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-08-01 19:03:32 -0500

vbplaya gravatar image

BLUF: Melodic uses Python 2 which requires a __init__.py file in each folder containing python scripts.

I found out what the issue is. Melodic uses Python 2 by default and Noetic uses Python 3 by default. I have only worked in Python 3 and didn't know that if I want to import a python file from a folder that you must include a __init__.py file in that folder (even if it is empty).

So to get it to work I just had to put a __init__.py file into the gui_templates folder, run catkin_make, source devel\setup.bat ... and then it worked. I still need to type in: rosrun gui_pkg scripts/main.py but now if finds all the other python files.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-08-01 14:06:05 -0500

Seen: 58 times

Last updated: Aug 01 '22