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

catkin_create_pkg

asked 2016-12-05 08:20:29 -0600

raada gravatar image

updated 2016-12-05 10:53:09 -0600

gvdhoorn gravatar image

Hi,

I installed ROS Kinetic on Ubuntu 16.04 into Docker container. I created catkin workspace according to beginners tutorial. But when I try to create package, I get following exception:

$ catkin_create_pkg ahoj
Traceback (most recent call last):
  File "/usr/local/bin/catkin_create_pkg", line 68, in <module>
    main()
  File "/usr/local/bin/catkin_create_pkg", line 61, in main
    newfiles={})
  File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/package_templates.py", line 209, in create_package_files
    _safe_write_files(newfiles, target_path)
  File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/package_templates.py", line 185, in _safe_write_files
    fhand.write(content)
TypeError: a bytes-like object is required, not 'str'

Did you meed this situation somebody? It seems like function _safe_write_files fhand.write expects different data type than what it gets, but I don't understand why.

Thanks in advance for any idea, Radim

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-12-05 09:42:47 -0600

Dirk Thomas gravatar image

Your stacktrace shows that you have installed catkin_pkg for Python 3.5. The Debian package provided in the Xenial repository from ROS is using Python 2. So it looks like you have diverged from how you setup ROS on your machine.

You should uninstall catkin_pkg from /usr/local and follow the installation instructions: http://wiki.ros.org/kinetic/Installat...

edit flag offensive delete link more

Comments

Thank you - this was the reason!

I installed MORSE simulator from source code that requires python3 and I built catkin_create_pkg using python3 as its dependency. So the problem was between chair and keyboard;-)

raada gravatar image raada  ( 2016-12-05 10:48:15 -0600 )edit
0

answered 2021-03-29 00:28:56 -0600

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes instead. We can convert bytes to string using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is "utf-8" , so you can use directly:

b"python byte to string".decode("utf-8")

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-05 08:20:29 -0600

Seen: 1,107 times

Last updated: Mar 29 '21