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
.
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?
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.
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.
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.
Option 1 - Select parts of the code and hit F9 This runs the selected code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With