I'm trying to run commands on a robot running ROS using a python script with paramiko. Bascially, I have a python script on my computer that I want to connect to the robots to run a python script located on the robots. When I run the command in terminal over SSH directly, it works properly. However, when I run the exact same command using my script with paramiko, it gives me an import error-no module named rospy which I understand in theory because rospy is imported in my python script, but I don't understand why it would not have the same error when I run the exact same command over SSH in the terminal.
I have printed the command and checked that it is exactly the same (from everything that I can tell, at least), but I still get different results when I run these directly. Other commands seem to execute properly, but this one is causing problems.
This is the script on my computer I run to connect using paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=robot_ip, username=robot_user, password=robot_pass)
try:
command = "python ~/SchedulerInitiator.py " + str(initial_turn_angle) + " " + str(dist) + " " + str(final_turn_angle)
print(command)
stdin, stdout, stderr = ssh.exec_command(command)
except paramiko.SSHException:
print("Request rejected or channel closed")
print(stdout.readlines())
print(stderr.readlines())
These are the imports on the file called by SchedulerInitiator.py
from SchedulerHandler import *
import threading
import sys
and then rospy is imported in SchedulerHandler which is causing the actual problem.
Here is the error that prints when I run the code:
[u'Traceback (most recent call last):\n', u' File "/home/root/SchedulerInitiator.py",
line 1, in <module>\n', u' from SchedulerHandler import *\n', u' File "/home/root/SchedulerHandler.py",
line 7, in <module>\n', u' import rospy\n', u'ImportError: No module named rospy\n']
When I run that exact same command over SSH, it just runs with no error.
Any ideas what is wrong/how to fix this? Thank you!!