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.
Related
I am struggling on setting up pydev remote debugging feature.
I run Eclipse on my windows laptop and the code is on the linux server.
As far as I've understood the manual http://www.pydev.org/manual_adv_remote_debugger.html I have to have an exact local copy of the code to debug on my laptop and I need to link it with the code on the linux server with PATHS_FROM_ECLIPSE_TO_PYTHON variable. However no matter how I set this variable in the pydevd_file_utils.py on the server the paths in the error message don't change.
For each breakpoint I receive:
pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/user/D:\Workspace\RemoteSystemsTempFiles\****\home\user\Code\reco\Test2D.py (will have no effect)
Error message
How can I link this particular file, so I can debug it with breakpoints? Is a local copy of the file necessary, even though I can access the original file via windows network drive mapping?
Actually,
I have solved it in a not very intuitive way. For some reason, PATHS_FROM_ECLIPSE_TO_PYTHON variable in the pydevd_file_utils.py file didn't change the really used path for the server. I had to manually edit the _norm_file_to_server function in changing the path for the translated variable from _NormFile(translated) to the path of the debugged file e.g "home/user/code.py". After starting debug server I could start the execution of the file with a remote console, e.g python "home/user/code.py"and it worked properly by popping up and stopping at the breakpoint in eclipse.
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.
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.
I have a remote interpreter set up in PyCharm.
Everytime I close and reopen PyCharm, the connection seems to be broken, and the process to "reopen" the connection doesn't feel efficient to me.
Before doing the following, it is not possible to run any script.
Here is what I usually do:
File -> Settings
Project -> Project Interpreter
Click on the gear icon on the right.
Choose "More"
With my remote interpreter selected, click on "Edit"
Change "SSH Credentials" for "Deployment Configuration" (all the info is already filled)
Click "ok" multiple times to close everything up.
At that point, I can run any scripts on the remote machine.
What is the best/fastest way to do this? (any way to "save the settings"?)
Check option "Visible only for this project" of deployment configuration. This error occurs when the check mark is set.
https://www.jetbrains.com/help/pycharm/2018.3/deployment-connection-tab.html
if this checkbox is selected in an SFTP configuration, you cannot use
its SSH credentials for configuring a remote interpreter.
This was a bug in version 4.0.2 of PyCharm and was corrected in version 4.0.3.
Edit: No longer true. I tried with another computer and having the most recent version doesn't fix the problem.
i meet the same error, file->settings checking your interpreter setting,
You don't set the 'host' and 'post',or your set but the content was clear. check again, and it truly work
I'm looking for an IDE that will allow me to edit remote Python projects and also has decent Django support, remote command execution, and maybe remote debugging. I've tried PyCharm and Aptana with PyDev but I'm not having much luck configuring them for remote editing. Thanks for your help!
I have Pycharm setup on a Ubuntu 10.10. The key is to use "sshfs" - it maps to my web-host - via ssh. Those are the pre-reqs : ssh access, sshfs. (unless you can figure out a way to map ssh to a windows shared drive).
So once ssh, sshfs are setup, I create a linux mount locally - so my webhost's directory appears locally as "/webhostx" .. From then on Pycharm (or WingIde or any editor) does not care that "/webhostx" is really a remote folder mounted locally.
If all else fails there's always Emacs (everything included :-) ).
Pycharm also has a remote debugging feature - I am in the process of testing it with my host (webfaction).
Emacs has tramp for remote editing on top of ssh, ftp or other protocols(works out of the box). nxhtml has support for editing Django templates (needs setup). I don't know about remote debugging. I've never done that.
Of course, Emacs is a lifestyle rather than an editor as most of its users will tell you so be warned.
Try WingIDE.