Rosanswers logo

I'm trying to run

rosrun package python scripts

and get some errors below:

(cv-py3) hoang@hoang-Nitro-AN515-51:~/catkin_ws$ rosrun testpy test.py 
Parsing cfg/tiny-yolo-voc-3c.cfg
Traceback (most recent call last):
  File "/home/hoang/catkin_ws/src/testpy/src/test.py", line 41, in <module>
    tfnet = TFNet(options)
  File "/home/hoang/catkin_ws/src/testpy/src/darkflow/net/build.py", line 58, in __init__
    darknet = Darknet(FLAGS)
  File "/home/hoang/catkin_ws/src/testpy/src/darkflow/dark/darknet.py", line 17, in __init__
    src_parsed = self.parse_cfg(self.src_cfg, FLAGS)
  File "/home/hoang/catkin_ws/src/testpy/src/darkflow/dark/darknet.py", line 68, in parse_cfg
    for i, info in enumerate(cfg_layers):
  File "/home/hoang/catkin_ws/src/testpy/src/darkflow/utils/process.py", line 66, in cfg_yielder
    layers, meta = parser(model); yield meta;
  File "/home/hoang/catkin_ws/src/testpy/src/darkflow/utils/process.py", line 17, in parser
    with open(model, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'cfg/tiny-yolo-voc-3c.cfg'

Note: those errors stop when I run rosrun in the script's folder. But, I wanna add a node in package launch file to use roslaunch for python scripts.

What I need to do? Thanks in advance!

I followed these steps:

$ cd ~

$ mkdir catkin_ws/src -p

$ cd catkin_ws

$ catkin_make

$ cd src

$ catkin_create_pkg testpy rospy

this step I copy all scripts to package/src folder

$ cd ~/catkin_ws

$ catkin_make

$ . ~/catkin_ws/devel/setup.bash

$ roscore

$ chmod +x test.py (added #!/usr/bin/env python)

$ rosrun testpy test.py

Originally posted by MCVB on ROS Answers with karma: 1 on 2019-01-10

Post score: 0

Original comments

Comment by gvdhoorn on 2019-01-10:
Please copy-paste the errors directly into your question. Do not use screenshots. It's all text.

Comment by MCVB on 2019-01-10:
Ok, It was edited


1 Answer 1


Rosanswers logo

FileNotFoundError: [Errno 2] No such file or directory: 'cfg/tiny-yolo-voc-3c.cfg'

ROS changes the current working directory for nodes when using rosrun and roslaunch. You cannot use relative filenames then. Change it to an absolute path and it should work.

See #q33890 for a very old -- but still correct -- explanation of this.

Originally posted by gvdhoorn with karma: 86574 on 2019-01-10

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

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