Ask Your Question
2

Error on import ros packages

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

bxl gravatar image

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

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 imagejarvisschultz ( 2018-10-17 14:16:09 -0600 )edit

I check /usr/bin/ and it is empty

bxl gravatar imagebxl ( 2018-10-17 14:30:54 -0600 )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 imagejarvisschultz ( 2018-10-17 16:37:48 -0600 )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 imagejarvisschultz ( 2018-10-17 16:38:45 -0600 )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 imagejarvisschultz ( 2018-10-17 16:42:55 -0600 )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 imagejarvisschultz ( 2018-10-17 16:44:06 -0600 )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 imagejarvisschultz ( 2018-10-17 16:51:16 -0600 )edit

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

bxl gravatar imagebxl ( 2018-10-18 09:40:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
8

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 11,825 times

Last updated: Oct 19 '18