1

When trying to execute a python file through a paramiko SSHClient, I'm getting the error:

ImportError: No module named rospy

In the line of that file that contains the rospy import. I'm only getting this error when trying to run the code using paramiko i.e:

ssh=paramiko.SSHClient()
ssh.connect(ipaddress,22,username,pw)
stdin, stdout, stderr = ssh.exec_command('python path/to/file.py')

When executing the command through a terminal, it works as desired. I only get the import error when trying to use paramiko. I'm unsure as to why this is occurring and any assistance would be greatly appreciated. Thanks.

Edit: further tinkering and experimentation has shown that it is a path issue, but the path for both the computer I am using and the target device are the same, but when I run echo $PATH on paramiko, the path element /opt/ros/indigo/bin/ is not included

zgracia
  • 11
  • 2
  • Have you successfully tested running exec_command() with a simple Python file (e.g., a file that doesn't import any modules)? – nb1987 Apr 17 '18 at 16:08
  • 1
    You might need to install the rospy module of the targeted machine if the python distribution is different. – TwistedSim Apr 17 '18 at 16:09
  • yeah simple commands such as 'pwd' and 'ls' work fine – zgracia Apr 17 '18 at 16:16
  • Also the targeted machine has python 2.7.6 while mine has 2.7.12, could that be the root of the issue? – zgracia Apr 17 '18 at 16:20
  • 1
    I strongly suspect it has to do with the search path for modules, which could differ for your script's SSH session versus your terminal-based SSH session. For example, is your `PYTHONPATH` environment variable set on the target machine so scripts (local to the target machine) can import `rospy`? If this is the case, and assuming you're using a recent version of paramiko, you can pass an environment variable dictionary to `exec_command` – nb1987 Apr 17 '18 at 16:52

0 Answers0