Rosanswers logo

Hi, I am working on a project, and I want to start the different nodes using a launch file. In the latter I start one Python node and the other is an rqt plugin that I created:

    <node name="PiMaster_node" pkg="airplane_master" type="PiMaster.py" output="screen"/>
    <node name="airplane_master" pkg="airplane_master" type="airplane_master"/>

My problem is that when I run the two scripts separately using rosrun, everything works perfectly, but when I use roslaunch to start my .launch file I get this error:

Traceback (most recent call last):
  File "/home/micdev/catkin_ws/devel/lib/airplane_master/PiMaster.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/home/micdev/catkin_ws/src/airplane_master/scripts/PiMaster.py", line 21, in <module>
    logging.basicConfig(filename='src/airplane_master/src/airplane_master/Master.log', level=logging.ERROR,
  File "/usr/lib/python3.8/logging/__init__.py", line 1988, in basicConfig
    h = FileHandler(filename, mode)
  File "/usr/lib/python3.8/logging/__init__.py", line 1147, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.8/logging/__init__.py", line 1176, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/home/micdev/.ros/src/airplane_master/src/airplane_master/Master.log'

Basically it says that it couldn't find a Log file (that actually exists): I use the logging module in Python to log some infos in Master.log file... Maybe it is interacting with the ROS logger? If this is the case why doesn't it happen when I run the python file using rosrun? Can someone help me, I'm stuck :(

Thanks in advance!

Originally posted by Mix_MicDev on ROS Answers with karma: 23 on 2022-06-15

Post score: 0


1 Answer 1


Rosanswers logo

FileNotFoundError: [Errno 2] No such file or directory: '/home/micdev/.ros/src/airplane_master/src/airplane_master/Master.log'

Note how the path is /home/micdev/.ros/....

Is that where your log file is located?

Please note that when starting nodes using roslaunch, their working directory is set to $ROS_HOME, which in many cases is set to $HOME/.ros. In your case probably /home/micdev/.ros.

See #q235337, #q271442 and the linked Q&As there for more information.

Summarising: make sure you use absolute paths, not relative paths, or your scripts won't be able to find files they need.

Originally posted by gvdhoorn with karma: 86574 on 2022-06-16

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by Mix_MicDev on 2022-06-16:
Thank you for your answer! I am now using absolute paths like you said, and it's working. Here's how I'm finding the path of the file inside the Python code:

file_name = os.path.join(rospkg.RosPack().get_path('package_name'), 'file_directory', 'file_name')

Just to make sure, that's what you meant by "absolute paths" right?

Comment by gvdhoorn on 2022-06-17:
I would personally probably use a param as a child of the node and use substitution args to have roslaunch construct the path for me. Your node would then just have to read the parameter from the parameter server.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.