Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder, Run script located on remote server

Tags:

python

spyder

I am starting to use Spyder to edit code located on a remote server. I managed to connect to the kernel of my remote server. In order to be able to open and save (download, upload) the scripts, I installed Expandrive, that mapped the server as if it were an external hardrive on my machine. The server OS is Linux, my local one is Windows.

I thought that should work, but I am still receiving the error file not found.

enter image description here

Any idea why?

On that other post: Spyder: How to edit a python script locally and execute it on a remote kernel?, it is suggested (second answer) to add some specific code to the %run command file in order for the program to understand the dirpath syntax of linux.

    # ----added to remap local dir to remote dir-------     localpath = "Z:\wk"     remotepath = "/mnt/sdb1/wk"     if localpath in filename:         # convert path to linux path         filename = filename.replace(localpath, remotepath)         filename = filename.replace("\\", "/")     # ----- END mod 

Do you think that would adress my problem?

like image 821
jim jarnac Avatar asked Jan 08 '17 06:01

jim jarnac


People also ask

How do I run a Python script on a remote server?

Using the paramiko library – a pure python implementation of SSH2 – your python script can connect to a remote host via SSH, copy itself (!) to that host and then execute that copy on the remote host. Stdin, stdout and stderr of the remote process will be available on your local running script.

How do I run a Spyder script?

Execute a Script in Spyder To run a script in Spyder IDE, there are two options: use the command line option, use runfile in IPython.

How do I launch a Spyder in Linux?

Running Spyder You can launch it in any of the following ways: From the command line: Type spyder in your terminal (or Anaconda prompt on Windows). From Anaconda Navigator: Scroll to Spyder under Home, and click Launch.

How do you run chunk of code on Spyder?

Option 1 - Select parts of the code and hit F9 This runs the selected code.


1 Answers

The path for the %run magic needs to be the path that the server sees, not the client. You are passing the path from the client's perspective.

When you type run Z:/blah/blah/blah.py, your terminal sends that path to the IPython server to execute. The server looks for the path Z:/blah/blah/blah.py, but since it doesn't exist on the server, the command fails with a file not found error.

The easiest solution is to just run the command with the path the server expects:

%run /path/to/blah/on/server/blah.py


Bottom line: remember that the server cannot access files that the client terminal is running on.

like image 134
Cody Piersall Avatar answered Sep 28 '22 05:09

Cody Piersall