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

Error on import ros packages

asked 2018-10-17 14:00:09 -0500

bxl gravatar image

updated 2018-10-17 15:59:36 -0500

I`m trying to write a ros module in python, but I'm facing this issue below:

import: not authorized `rospy' @ error/constitute.c/WriteImage/1028.
from: can't read /var/mail/sensor_msgs.msg
from: can't read /var/mail/tf2_msgs.msg
from: can't read /var/mail/geometry_msgs.msg
from: can't read /var/mail/cv_bridge

Is there any configuration wrong in CmkaList.txt or package.xml? Am I missing any file for cmake compile correctly python code?

EDIT #1: Added code

#!/usr/bin/env python

import rospy
from sensor_msgs.msg import Image,CameraInfo
from tf2_msgs.msg import TFMessage
from geometry_msgs.msg import TransformStamped
from cv_bridge import CvBridge
import airsim
import cv2
import numpy as np here

EDIT #2: The script is already executable chmod u+x script.py

edit retag flag offensive close merge delete

Comments

2

Looks to me like this is most likely an issue with the #! at the beginning of your Python script. Can you please edit your question and copy-paste the first few lines of the script you are referring to?

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 14:16:09 -0500 )edit

I check /usr/bin/ and it is empty

bxl gravatar image bxl  ( 2018-10-17 14:30:54 -0500 )edit

That's strange. On most systems, at the terminal, if you just type /usr/bin/env python it should automatically launch your default Python interpreter. Does that work on your machine? If not, what Linux distro are you on? You could probably work around this issue by replacing the string after...

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 16:37:48 -0500 )edit

... the #! to just be the full path to your default Python executable. For example, #!/usr/bin/python . You could use which python in a terminal to figure out the full path of your default Python.

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 16:38:45 -0500 )edit

As a side note, the error/constitute.c/WriteImage/1028. error you are seeing is because your system is not properly using Python as the interpreter to parse this script. Instead it is likely using either sh or bash. The command import is part of ImageMagick so you are effectively trying to..

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 16:42:55 -0500 )edit

... run the ImageMagick command line tool import on a file named rospy , and that is throwing the error. To read more about this, check out the shebang Wikipedia page: https://en.wikipedia.org/wiki/Shebang...

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 16:44:06 -0500 )edit

One other thought.... are you sure that the #! is the absolute first two characters in the script? It is in the snippet you posted, but that could be a copy-paste relic. If you have a blank line at the top of your script, you'll get exactly the error you are showing.

jarvisschultz gravatar image jarvisschultz  ( 2018-10-17 16:51:16 -0500 )edit

I found the errror: there was a space before #!, at the beginning. Thanks @jarvisschultz for your help

bxl gravatar image bxl  ( 2018-10-18 09:40:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
17

answered 2018-10-19 11:34:41 -0500

updated 2018-10-19 11:35:55 -0500

Just to have this question marked as answered: from the discussion above, it became clear that the hashbang (#!) at the beginning of the Python file was not properly entered. It turns out there was an extra space before the # character.

For anyone reading this in the future, remember, there are 2 required steps to make any Python script run as a ROS node (or even more generally to make the script executable):

  1. The script must be executable by your user. This is typically done with chmod gu+x. I think this is a good tutorial on Linux permissions.
  2. You need to have a hashbang as the first 2 characters of the script to tell the OS which interpreter should interpret the script. This must be the very first 2 characters in the script. For Python we usually use #!/usr/bin/env python . The Wikipedia page on this is a good resource: https://en.wikipedia.org/wiki/Shebang...
edit flag offensive delete link more

Comments

Worked like a charm!!!

Robot gravatar image Robot  ( 2020-09-14 13:31:39 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-17 14:00:09 -0500

Seen: 27,783 times

Last updated: Oct 19 '18