pycharm ssh interpter No such file or directory
Question:
I am using a macbook pro 15 as local machine and I have a remote server running ubuntu 14.04
I want to use the remote intepreter to run all the computation but I want to write the code from my local machine.
When I try to run a simple file with pycharm I receive this error:
ssh://[email protected]:22/usr/bin/python3 -u /Users/donbeo/Documents/phd_code/prova.py
bash: line 0: cd: /Users/donbeo/Documents/phd_code: No such file or directory
/usr/bin/python3: can't open file '/Users/donbeo/Documents/phd_code/prova.py': [Errno 2] No such file or directory
Process finished with exit code 2
I saw few people reporting the same problem but I haven’t found a good answer so far. Most of the questions are indeed referring to older versions of pycharm.
It is clear that the file is not in my remote machine because I create it with pycharm in my local one. I was expecting pycharm to do some sort of synchronisation between the local and remote machine.
Answers:
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.
It can be caused by one of the following:
1. You did not deploy your code on the remote server.!
- Make sure that the recent edition of your code is deployed on the server. You can always deploy your code from Tools -> Deployment -> Upload to …, or by using Ctrl + Shift + Alt + x.
- For setting the deployment path, Go to File -> Settings -> Build, Execution, Deployment -> Deployment, and enter a remote sever details as your deploying machine.
- In the Mappings tab, make sure that the deployment path is defined somewhere on the server where you have permission to read and edit files there.
2. You do not have the permission to read and change files on your deployment path at the remote server.
- Go back to File -> Settings -> Build, Execution, Deployment -> Deployment, and change deployment path on the Mappings tab.
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 to Run->Edit Configurations...->Environment Variables
and add your project’s root path to the PYTHONPATH
variable.
I’m running PyCharm 2018.3
The Problem:
First, I didn’t have the [Errno 2] No such file or directory
problem. Then I had the problem out of nowhere.
The issue arose when I did:
- Preferences -> Project: {project_name} -> Project Interpreter
- Instead of "Click on cog icon and select Add Remote", I chose a interpreter that I’ve configured previously (that is working fine previously) from the drop down menu
By doing the steps above, I had [Errno 2] No such file or directory
problem.
The reason is that the folder is not automatically synced to the remote server (a bug?), nor could I find a way to configure it to sync. Configuring Deployment
and Path Mappings
did work, but it’s too much manual labor and prone to error.
The solution:
All I had to do is to add a new remote interpreter, despite that identical configurations already exists previously. (To be safe, I did remove the old ssh interpreter and the old deployments, also removed .idea folder) Then everything worked as expected.
- I didn’t need to configure Deployment
- I didn’t need to configure Paths mappings
For those who meet the problem like "miniconda3/envs/gpu/bin/python: can’t open file ‘///home/…/test.py", you can just run the python script file in locality in pycharm rather than run the file in server in pycharm.
I am using a macbook pro 15 as local machine and I have a remote server running ubuntu 14.04
I want to use the remote intepreter to run all the computation but I want to write the code from my local machine.
When I try to run a simple file with pycharm I receive this error:
ssh://[email protected]:22/usr/bin/python3 -u /Users/donbeo/Documents/phd_code/prova.py
bash: line 0: cd: /Users/donbeo/Documents/phd_code: No such file or directory
/usr/bin/python3: can't open file '/Users/donbeo/Documents/phd_code/prova.py': [Errno 2] No such file or directory
Process finished with exit code 2
I saw few people reporting the same problem but I haven’t found a good answer so far. Most of the questions are indeed referring to older versions of pycharm.
It is clear that the file is not in my remote machine because I create it with pycharm in my local one. I was expecting pycharm to do some sort of synchronisation between the local and remote machine.
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.
It can be caused by one of the following:
1. You did not deploy your code on the remote server.!
- Make sure that the recent edition of your code is deployed on the server. You can always deploy your code from Tools -> Deployment -> Upload to …, or by using Ctrl + Shift + Alt + x.
- For setting the deployment path, Go to File -> Settings -> Build, Execution, Deployment -> Deployment, and enter a remote sever details as your deploying machine.
- In the Mappings tab, make sure that the deployment path is defined somewhere on the server where you have permission to read and edit files there.
2. You do not have the permission to read and change files on your deployment path at the remote server.
- Go back to File -> Settings -> Build, Execution, Deployment -> Deployment, and change deployment path on the Mappings tab.
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.
I’m running PyCharm 2018.3
The Problem:
First, I didn’t have the [Errno 2] No such file or directory
problem. Then I had the problem out of nowhere.
The issue arose when I did:
- Preferences -> Project: {project_name} -> Project Interpreter
- Instead of "Click on cog icon and select Add Remote", I chose a interpreter that I’ve configured previously (that is working fine previously) from the drop down menu
By doing the steps above, I had [Errno 2] No such file or directory
problem.
The reason is that the folder is not automatically synced to the remote server (a bug?), nor could I find a way to configure it to sync. Configuring Deployment
and Path Mappings
did work, but it’s too much manual labor and prone to error.
The solution:
All I had to do is to add a new remote interpreter, despite that identical configurations already exists previously. (To be safe, I did remove the old ssh interpreter and the old deployments, also removed .idea folder) Then everything worked as expected.
- I didn’t need to configure Deployment
- I didn’t need to configure Paths mappings
For those who meet the problem like "miniconda3/envs/gpu/bin/python: can’t open file ‘///home/…/test.py", you can just run the python script file in locality in pycharm rather than run the file in server in pycharm.