pycharm ssh interpter No such file or directory - python

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://donbeo#149.157.140.205: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.

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.

Be sure your interpreter is chosen as SSH which is to compile, not STFP which is for deployment.

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

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.

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.

Related

PyCharm Error when setting remote interpreter -> Run Error: Jupyter server process failed to start due to path mismatch issue

I am trying to setup remote development on PyCharm. For this, I want to make changes locally and execute the code on remote Amazon EC2 instance with a remote interpreter. I had done the following configuration of the project, but I am getting run error when I try to execute a ipython file created locally.
Cannot run program "stfp://<remote server hostname>/<remote server host>:<remote interpreter path>" (in directory <local folder directory>): error=2, No such file or directory.
It seems it should open <remote folder directory> instead of <local folder directory> when running the program. I read through multiple setup instructions but could not get this fixed. I am attaching configuration below.
Can you please help me with what could be wrong?
Updating PyCharm to 2022.3 can fix the issue. This seems to be related to an unstable older version.

Pycharm Remote interpreter on Docker remote: [Errno 2] No such file or directory

As specified in the title I am trying to use Pycharm Professional (2018.2) with a python remote interpreter in a Docker machine hosted on a remote server in my LAN. I created a very simple example by following the help 'https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html'.
Pycharm 2018.2 is installed on a LAN pc (192.168.1.10) on a debian distro;
Docker is installed on a LAN debian server (192.168.1.22)
I was able to configure Docker as a remote interpreter, to connect with the Docker service through the Pycharm tool but when I try to run (or debug) the main.py in the Docker container I always get this:
37073edcd9d2:python -u /opt/project/main.py (null): can't open file '/opt/project/main.py': [Errno 2] No such file or directory
Process finished with exit code 2
The execution is certainly done in the remote Docker container but it seems that the file to be executed is not found. I manually attached the local volume as described on various blogs with all possible variations but I always get the same error.
These are some specifications of my configuration:
docker tool setting
project interpreter setting
Run/Debug Configuration
docker container setting with volume mapping into Run/Debug Configuration
Is missing something?
Tanks. Any help is appreciated!
The problem lies in the Pycharm 'limit' of managing a docker machine on a remote host 'under the hood'. When inserting the volume mapping in the run / debug configuration, it is interpreted as a local path and therefore, in this case, a path that must be present on the remote server. So, for now, the only option is to mount the local path (the folder where the project is located) on the remote host of the Docker service by first sharing it through an SSHFS or NFS service.
So ... (1) I shared the Pycharm project folder (local machine ip 192.168.1.10) using NFS; (2) I mounted the shared folder on the server host (on server ip 192.168.1.22; mount -t nfs 192.168.1.10:/home/user/PythonProjects /home/ext-user/mnt/projects) then (3) in the run / debug configuration of Pycharm I mapped the volumes with the path mounted on the remote server ... Run ... the program now runs without any errors. [Run result]
These are some specifications of my new configuration:
Run/Debug Configuration
docker container setting with volume mapping into Run/Debug Configuration
I hope the solution can be useful to other people. I also hope that there are better solutions than mine :-)

Python run via ssh bur edit locally [duplicate]

This question already has answers here:
How do I start up remote debugging with PyCharm?
(3 answers)
Closed 4 years ago.
I am using PyCharm in ubuntu. I have access to an external server to which I connect my PC via ssh.
How can I edit codes using PyCharm on my PC but run the codes within PyCharm (by hitting Ctrl+F5 to be clear, so without the server's terminal) using the server's python (and computing power)?
Is there any other IDE capable of doing it?
Also, if inputs are needed and outputs are created, can they be stored locally on my PC?
Thanks!
Yeah, but you need Professional version of PyCharm.
First, you need to establish an interpreter:
Go to File -> Settings -> Project -> Project Interpreter -> wheel button -> Add -> SSH Interpreter.
Configure host, port, username and press Next.
Configure your authentication option (password or key pair).
Press Next and configure your python environment (by default: /usr/bin/python). You can put here your Python executable of your virtualenv.
Second, configure Deployment:
Go to File -> Settings -> Build, Execution, Deployment -> Deployment.
Add a new one by hitting the + green button.
In Type, choose SFTP.
Configure host, port, username and authentication in Connection.
In Mappings, you need to configure where the project is on your local and remote hosts.
Then, in Tools -> Deployment, check "Automatic Upload (always)".
Now, when you hit Ctrl + S to save, or run your project, it automatically saves in your local and remote hosts, and runs in the remote server.
If you need to access to the files in the remote host, you can add an FTP view in Tools -> Deployment -> Browse Remote Host.

Opening remote project in PyCharm

I'm working on a project that is located in a remote server. Can I open it in PyCharm from my local machine ? I couldn't find the way.
The way I access the projects on my raspberry pi using PyCharm is the following (This expects you to be using PyCharm Pro, supporting SSH connections):
Mount the home folder on my local machine ( I use SFTP Drive on windows, under Linux use sshfs).
Open the project from the mounted drive in PyCharm
Go to Settings -> Project -> Project Interpreter and select the gear next to the Project Interpreter drop down. From there pick "Add Remote".
Configure the remote interpreter you want to use.
If the PyCharm project was already created on the server, I guess your run configuration should be in order and running it should work out of the box.
If you created the PyCharm project on your local machine:
If you have no run configuration yet, go to the file you want to run and do right-click -> Run yourfilename.py or simply hit Shift-F10
The remote interpreter will complain about non existent files. Go to the dropdown in the top right corner, click it and select 'Edit Configurations'
Change the script path and working directory to the actual remote directories. Remember, this is what your interpreter sees, and your interpreter is on your remote machine.
Hope this helps!
The following will configure PyCharm Professional 2021.3.1 on Windows 10 to run a project on a remote Linux server. It's likely the configuration will be similar for PyCharm on macOS.
Open PyCharm
Create a New Project and select Pure Python
Fill the Location and Remote project location, which may be new or existing.
Select the ellipsis next to Interpreter under Previously configured interpreter
Select SSH Interpreter and create New server connection
Supply your credentials
The default Interpreter will be /usr/bin/python, but an alternate location may be provided, for example /home/.../anaconda3/bin/python3.9
Create the project
Press Ctrl + Alt + S to open Settings
Select Deployment under Build, Execution, Deployment
Check Connection and Test Connection
Check Mappings to verify Local path and Deployment path
Select Python Interpreter under Project:...
Verify the remote interpreter is selected for the project.
As long as this is the case, the code will run relative to the remote system.
Close Settings with OK, or Apply
Use PUTTY or some other app to verify the project now exists on the remote system
Right click the project and select Deployment for deployment options
Note
This will likely require being connected to the corporate network through a VPN.
To update on excellent #Skusku answer given here:
https://stackoverflow.com/a/47614111/2119941
After mounting remote folder with SFTP Drive if Pycharm project browser doesn't recognize remote drive just copy-paste it in location bar on top and allow Pycharm to load it:
And when you load your project files to Pycharm you need to add remote interpreter which is present on your server:
In following screens just add host, credentials and than path to python in virtual env or whatever python is running your server project files.
Pycharm needs access to the project's directory.
You can open a remote project if the storage partition for that project directory is shared and mounted/mapped on your local machine with the right permissions by running pycharm on your machine and opening that locally visible project directory.
Note: you should not be opening the project in multiple such pycharm sessions simultaneously as they will collide/conflict with each-other.
Alternatively if you use a version control system (VCS) that supports remote repository access you can create a local copy of the project, work in that copy and push your changes to the remote project as needed (depending on your VCS specifics).
Search remote sync under plugins in pycharm. Many work. I think most common one is source sync.

Remote debuging on Pycharm is concatenating local and remote path

I have a problem that I haven't been able to find an answer to.
I'm trying to debug a Python program running on a Raspberry Pi. The source code is located on my PC.
I set up an FTPS deployment and remote interpreter over ssh.
When I just run the app on the remote Raspberry Pi there are no problems.
The problem appears while I try to set up a breakpoint. In this case pydev writes:
>pydev debugger: warning: trying to add breakpoint to file that does not exist:
/home/pi/python/f:/python projects/server/server.py (will have no effect)
Pycharm thinks that the path to the app is the path on the remote computer + the path on the local computer.
Does anyone know what setting might be causing this and how to fix it?
From Run/Debug Configuration: Python section of PyCharm 3.4.0 Web Help:
Path mappings –
This field appears, if a remote interpreter has been
selected in the field Python interpreter. Click the browse button
to define the required mappings between the local and
remote paths. In the Edit Path Mappings dialog box, use add/delete
buttons to create new mappings, or delete the selected ones.
Configuring this option in your debug configuration should solve your problem.
Maybe it's obvious, but I was getting the same problem when using ~ instead of writing out the whole path of my home directory for the remote mapping.

Categories