ROS Melodic no longer finding python scripts
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 guitemplates.txrx_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
- txrxdisplay.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)
Asked by vbplaya on 2022-08-01 14:06:05 UTC
Answers
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.
Asked by vbplaya on 2022-08-01 19:03:32 UTC
Comments