1

I have following task: I have Linux (RedHat) server and Windows machine. I need to execute Python script located on Windows side from Linux using ssh. SSH server with password-less access is configured on Windows machine. I tried following command:

$ ssh sshuser@windows_host_IP /drives/c/Users/sshuser/PythonScripts/myscript.py
C:\ProgramData\Anaconda3\python.exe: can't open file '/drives/c/Users/sshuser/PythonScripts/myscript.py': [Errno 2] No such file or directory

Then i tried this:

$ ssh sshuser@windows_host_IP C:/Users/sshuser/PythonScripts/myscript.py
Traceback (most recent call last):
  File "C:/Users/sshuser/PythonScripts/myscript.py", line 3, in <module>
    import pandas as pd
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

This looks more like Python error, but script works normally on Windows side.

Could you please suuggest what I am doing wrong?

Thank you in advance.

2

Using that way, you're currently running your script on Windows ... is it really the goal ?

If yes, then i guess that your SSH session is probably missing a correctly set PYTHONPATH because the error reported is that it just can find the numpy module. I don't really know how python works under Windows but, in my opinion, it's probably because your sshuser don't have access to numpy module (maybe installed using another user ?).

If you want to execute the script under Linux after fetching it from the windows host, then you probably should run

sshuser@windows_host_IP "type C:/Users/sshuser/PythonScripts/myscript.py" | python -

This command will makes windows dump the script to stdout and pipe it to your local pyton interpreter

  • Yes, my goal is to run script on Windows machine. – user374596 Sep 27 '19 at 9:45
  • 1
    So you have to dig regarding PYTHONPATH-like settings under windows or ask on another stackexchange cause Unix & Linux StackExchange isn't the best place to solve windows issues ;-) – binarym Sep 27 '19 at 9:47
  • Thank you for your idea. There was issue with PYTHONPATH for correct user. It was configured but for another user. Now it is solved. – user374596 Sep 27 '19 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.