Remote development with PyCharm

PyCharm is a fantastic tool for python development. One cool feature that I quite like is its support for remote development. We have quite a few projects that need to interact with special hardware, and that hardware is often not attached to the computer we’re developing on.
In order to test your programs, you still need to run it on that computer though, and doing this without tool support can be especially painful. You need to use a tool like scp or rsync to transmit your code to the target machine and then execute it using ssh. This all results in painfully long and error prone iterations.
Fortunately, PyCharm has tool support in its professional edition. After some setup, it allows you do develop just as you would on a local machine. Here’s a small guide on how to set it up with an ubuntu vagrant virtual machine, connecting over ssh. It work just as nicely on remote computers.

1. Create a new deployment configuration

In the Tools->Deployment->Configurations click the small + in the top left corner. Pick a name and choose the SFTP type.
add_server

In the “Connection” Tab of the newly created configuration, make sure to uncheck “Visible only for this project”. Then, setup your host and login information. The root path is usually a central location you have access to, like your home folder. You can use the “Autodetect” button to set this up.

connection
For my VM, the settings look like this.

On the “Mappings” Tab, set the deployment path for your project. This would be the specific folder of your project within the root you set on the previous page. Clicking the associated “…” button here helps, and even lets you create the target folder on the remote machine if it does not exist yet.

2. Activate the upload

Now check “Tools->Deployment->Automatic Upload”. This will do an upload when you change a file, so you still need to do the initial upload manually via “Tools->Deployment->Upload to “.

3. Create a project interpreter

Now the files are synced up, but the runtime environment is not on the remote machine. Go to the “Project Interpreter” page in File->Settings and click the little gear in the top-right corner. Select “Add Remote”.

remote_interpreter
It should have the Deployment configuration you just created already selected. Once you click ok, you’re good to go! You can run and debug your code just like on a local machine.

Have fun developing python applications remotely.

6 thoughts on “Remote development with PyCharm”

  1. 10x for the detailed info.
    My situations is a little different. the source files are stored remotely
    Instead of editing them using emacs via ssh I would like to use PyCharm from my local machine.
    Do you know how can I set it up to allow remote editing ?
    (I assume a cache folder will be used in my local machine, which is fine)

    1. I guess you could copy the code from the remote machine to the local machine first and then work as in my example. PyCharm actually lets you do this from the IDE. Does that help?

  2. For the security reasons, it is not allowed to create a local working copy of the project files on a local machine. Hence, I would like to work directly on remote files (e.g. as you can in sublime) and run the interpreter remotely.

    Does anybody know how to set up this work environment?

  3. Thanks. Now (four and a half years later) there are some changes in PyCharm, most notably, instead of “Add Remote”, you do it as “Python Interpreter > [Gear Icon] >Add > SSH Interpreter > Existing server configuration”,

    but other than that (mostly), it still works 😉

Leave a reply to toboli Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.