Ask Your Question
0

Error: bad interpreter: No such file or directory

asked 2018-10-23 03:07:20 -0600

Spyros gravatar image

updated 2018-10-23 03:40:13 -0600

gvdhoorn gravatar image

I am trying to run the following node using rosrun, to send data through my serial port and I get the error:

/opt/ros/kinetic/bin/rosrun: /home/spyros/catkin_ws/src/usb_rs232/scripts/serial_connection.py: /opt/bin/python: bad interpreter: No such file or directory
/opt/ros/kinetic/bin/rosrun: line 109: /home/spyros/catkin_ws/src/usb_rs232/scripts/serial_connection.py: Success

Also, when I compile the code with catkin_make, my node isn't on the list of: Built target [my_node]

The first version of the code (outside ROS-only python script) works fine. I think the problem has to be in the modification of the code, to run it as a ROS node.

Do you have any possible solution, or a hint of what might be the problem here? I am new to ROS. I use Ubuntu 16.04, ROS kinetic, Python 2.7

Thanks in advance!

#!/opt/bin/python
#!/usr/bin/env python
import rospy
import serial
import time
from std_msgs.msg import String
def serial_connection():
    rospy.init_node('serial_connection', anonymous = True)
    rate = rospy.Rate(10)
    syxnotita = 0
    euros = 0
    mesi_gwnia = 0
    while not rospy.is_shutdown():
        data = [syxnotita, euros, mesi_gwnia]
        ser = serial.Serial('/dev/ttyUSB0', 9600)
        print (ser.name)
        time.sleep(2)
        while ser.isOpen():
            print ("Port Open")
            for i in range(5):
                print ('Hola!')
                ser.write("Hola!\n")
                time.sleep(1)
                rate.sleep()
        ser.close()
if __name__ == '__main__':
    try:
        serial_connection()
    except rospy.ROSInterruptException:
        pass

Edit: The output is:

ls: cannot access '/opt/bin/python': No such file or directory

I used the same interpreter (#!/opt/bin/python) when I run the python script (outside ROS) from my terminal. Then I added the line #!/opt/bin/env python following the steps of the tutorial for python subscriber node.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-23 03:17:31 -0600

gvdhoorn gravatar image

updated 2018-10-23 05:45:23 -0600

/opt/bin/python: bad interpreter: No such file or directory

Do you have a python binary in /opt/bin? What is the output of ls -al /opt/bin/python?

If not, why do you specify that as the interpreter to be used for this file?


Edit:

The output is: ls: cannot access '/opt/bin/python': No such file or directory

Then it would appear there is no interpreter (or at least: no binary) there and you cannot specify it as the one to use for this file.

I used the same interpreter (#!/opt/bin/python) when I run the python script (outside ROS) from my terminal.

I'm not saying you're lying, but I would find that really strange: ROS does nothing special here. It certainly doesn't change any of your Python interpreters or where they are located.

If there is no file at /opt/bin/python, then you cannot specify it as the interpreter to use for that file. With or without ROS.

Then I added the line #!/opt/bin/env python following the steps of the tutorial for python subscriber node.

I believe you mean: #!/usr/bin/env python: that makes more sense, as /usr/bin/env will figure out which python binary to use based on your current settings.

Suggestion: remove #!/opt/bin/python from your file.


Edit 2:

Reinstalletion worked ok, but after:

/usr/bin/env python -c 'import yaml'

I get:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named yaml

which python gave me:

/usr/local/bin/python

Without restarting laptop or terminal.

Now we're getting somewhere.

You do have a non-system-default Python interpreter on your system (it is a Python 2.7.15, while the normal Python version for Ubuntu 16.04 is actually 2.7.12) and it is taking precedence over the Ubuntu provided python.

The python-yaml Debian package only installs the yaml module for the system-default Python interpreter, so it makes sense that your custom Python interpreter cannot find it.

I don't know why you have that non-default Python in /usr/local/bin, but you'll either have to remove it or make sure that all modules required for ROS are also installed for the custom Python.

edit flag offensive delete link more

Comments

I removed that line and I run it again. I got the error:

ImportError: No module named yaml

My node was not at the Built list after I run catkin_make again.

Spyros gravatar imageSpyros ( 2018-10-23 03:56:09 -0600 )edit

Do you have Anaconda or some other alternative Python interpreter installed?

What is the output of dpkg -l | grep python-yaml?

gvdhoorn gravatar imagegvdhoorn ( 2018-10-23 04:00:26 -0600 )edit

The output is:

ii  python-yaml                                  3.11-3build1                                          amd64        YAML parser and emitter for Python

No, I don't thing I have Anaconda or other Python interpreter.

Spyros gravatar imageSpyros ( 2018-10-23 04:04:23 -0600 )edit

Ok. What is the output of /usr/bin/env python --version and /usr/bin/env python -c 'import yaml'?

gvdhoorn gravatar imagegvdhoorn ( 2018-10-23 04:20:32 -0600 )edit

I get: Python 2.7.15 and:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named yaml
Spyros gravatar imageSpyros ( 2018-10-23 04:25:00 -0600 )edit

Can you run any ROS nodes? What does running roscore print fi? Does that also complain?

gvdhoorn gravatar imagegvdhoorn ( 2018-10-23 04:40:49 -0600 )edit

roscore looks working ok. But I get the same error when I try to run some other ROS nodes.

ImportError: No module named yaml
Spyros gravatar imageSpyros ( 2018-10-23 05:18:59 -0600 )edit

Try this:

sudo apt-get install --reinstall python-yaml

then try this again:

/usr/bin/env python -c 'import yaml'

And for good measure: what is the output of:

which python
gvdhoorn gravatar imagegvdhoorn ( 2018-10-23 05:20:28 -0600 )edit

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-23 03:07:20 -0600

Seen: 1,255 times

Last updated: Oct 23 '18