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.
Related
So I have mounted a part of a development server which hold a virtual environment that is used for development testing. The reason for this is to get access to the installed packages such as Django-rest-framework and Django itself and not having it set up locally (to be sure to use the same version as the development server has). I know that it's perhaps better to use Docker for this, but that's not the case right now.
The way I've done it is installing SSHFS via an external brew (as it's no longer supported in the brew core) - via this link https://github.com/gromgit/homebrew-fuse
After that I've run this command in the terminal to via SSH mount the specific part of the development server that holds the virtual enviornment:
sshfs -o ssh_command='ssh -i /Users/myusername/.ssh/id_rsa' myusername#servername:/home/myusername/projectname/env/bin ~/mnt/projectname
It works fine and I have it mounted on my local disk in mnt/projectname.
Now I go into VSCode and go into the folder and select the file called "python3" as my interpreter (which I should, right?). However, this file is just an alias, being 16 bytes in size. I suspect something is wrong here, but I'm not sure on how to fix it. Can someone maybe take a look and give some input? I'll attach a screenshot of the mounted directory.
Screenshot of virtualenv directory mounted on local machine
The solution to the problem was using the VSCode extension Remote - SSH and run VSCode directly in the remote location, and from there being able to access the virtual environment.
I have anaconda, hence spyder, installed on a local machine. What I am trying to do is to use my local spyder installation to open a .py script saved on a remote cluster (in my office) via ssh. The issues that I am encountering are the following:
I cannot run spyder from the cluster - there is no graphical device whatsoever. For example, we have actually anaconda installed on the cluster, but when I ran spyder from the command line, I get the following error message: Could not connect to any X display
I cannot mount the (remote) drivers, where the .py scripts are located, onto my local machine when I am working from home (which is the case when I am at work, connected to the internet via cable). If this was the case, I could simply launch spyder on my local machine, then open the scripts. I can only access the files on some drivers mounted onto the cluster via ssh.
As, however, I can access the .py scripts saved on the cluster via ssh (I can open then with programs installed locally e.g. vim, jpico etc), I was wondering whether it is possible to use the command line to open a script saved on a remote cluster using my local spyder installation, something like $ spyder /path/to/myScript/savedOnTheRemoteCluster.py
(Spyder maintainer here) As of May 2019 our editor is not capable of working with files on remote locations. So your best option right now is to mount your remote server with sshfs to make it appear as a local directory and then open any file present there in Spyder.
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 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.
I have the remote server with a few virtualenv environments (django projects).
How can I open, develop and debug these projects completely remote?
Shall I mount remote directory via sshfs to open a project?
(I can't open project other way than as local path)
I am working on debian and windows xp.
I've found the decision and asked the support which confirmed its:
Here is the steps:
copy a project to a local directory.
configure: tools - deployment, to upload this local copy to remote server
make deployment automatic: tools - deployment - "automatic upload"
add remote interpreter: file - settings - python interpreters - "+" - "Remote.."
The remote interpreter is the virtualenv interpreter with all packages are installed.
Debug also works, we can debug completely remote project on server using local pycharm.
Debian:
From the file manager, click on Connect To server, connect to ssh by giving login credentials which will open your remote project on your file manager itself.
Or you can go to the server using ssh via terminal and edit your project via command line text editor.
IDE:
If you are working with IDE such as Aptana or PyCharm, you can load the project from the server itself by login credentials.