pycharm ssh interpter No such file or directory
Sometimes you can have everything set up correctly (interpreter, deployment, Path mapping, etc) but PyCharm keeps trying to use your local path on the remote machine.
If this happens, try this 4 fixes:
- Go to
File->Invalid Caches / Restart
...if the problem is still not fixed:
- Go to
Preferences->Python Interpreter->Path Mappings
and check the path mappings of the interpreter. They should look more or less like this:
...again, if the previous step didn't work:
- Go to
Run->Edit Configurations...
and check if the path mappings are correct:
- You can also try to replace the local paths of the script and working directory with the remote ones (as if you were already in that machine).
- If you get
ModuleNotFoundError
but the connection seems to work, go toRun->Edit Configurations...->Environment Variables
and add your project's root path to thePYTHONPATH
variable.
To execute your code on remote machine you'll have to perform few steps
Define a remote interpreter for your project
- Go to File -> Settings -> Project: {project_name} -> Project Interpreter.
- Click on cog icon and select Add Remote.
- Add your SSH host credentials and interpreter path (on remote machine).
- As a result, you should see new position in project interpreter dropdown selector, spelled like
Python Version (ssh://login@host:port/path/to/interpreter)
. Package list should be populated with records.
Define deployment settings
- Go to File -> Settings -> Build, Execution, Deployment -> Deployment
- Create new deployment settings and fill ssh host configuration
- Type: SFTP
- SFTP host: same as interpreter host
- Root path: path where files will be uploaded
- Click on button "Test SFTP connection" to check if provided data are correct.
- Go to mappings and configure mapping between local path and deployment path. Deployment path is relative to root path -
/
is equivalent to/my/root/path
,/dir
to/my/root/path/dir
etc.
Deploy your code
- Select Tools -> Deployment -> Upload to {deployment settings name}
- Upload process will be started in background. Wait for upload to complete.
Run your code
- Right click on file you want to run and select "Run". Code should run on remote machine.