This blog post is from 2015. If you are using PyCharm 2018.1 or later, see this blog post instead.
Happy Friday everyone,
In today’s blog post I’m going to cover some basic principles and features in PyCharm that make Python remote development easy as pie. To demonstrate them I’ll use a very simple flask web application from the official flask github repository. Enjoy the read!
Note: Remote development functionality is only available in PyCharm Professional Edition. For more details please see the editions comparison page.
First I clone the official flask repository from https://github.com/mitsuhiko/flask. Then from the PyCharm’s Welcome screen I open the blueprintexample directory, which stores the source of the super simple flask application I’m going to use for the demo:
PyCharm opens the directory and creates a project based on it:
Now I’m going to set up the remote machine to start with the remote development. I use Vagrant which PyCharm offers great support for. In one of my previous blog posts I already covered Vagrant integration, so here are just the straight steps to provision and run a VM. I go to Tools | Vagrant | Init in Project Root and select the Ubuntu 14.04 image which was previously imported from the collection of vagrant boxes. This creates the Vagrantfile in the project root. Now, I’m going to edit this file to configure a private network and make my VM visible from my host machine:
Next, I run the VM with Tools | Vagrant | Up and PyCharm shows me that the VM is up and running:
We can open a local terminal inside PyCharm to test the VM:
Alright, the VM responses to ping. Now, I want to run my web application on the VM, so I need to copy my project sources to the remote host. This is easily done with the Deployment tool inside PyCharm.
I go to Tools | Deployment | Configuration and specify the connection details for my VM:
On the Mappings tab in the same window I specify the path mapping rule:
In my case I want my current local project directory blueprintexampe to be mapped to remote /home/vagrant/blueprintremote.
Now I can right-click my project in the project view and select Upload to:
And this will upload my project to the specified directory on the remote machine:
One of the handiest features is that you can set up automatic upload to the remote machine by simply clicking Tools | Deployment | Automatic Upload:
From this point on, all changes made locally will be uploaded to the remote machine automatically, so you don’t need to worry about having fresh sources on the remote host. Cool, isn’t it?
So now, I’m going to modify one of the files in my project, so the flask application will be visible remotely (adding host=’0.0.0.0’ as a parameter to the app.run() ), and PyCharm automatically uploads the changes to the remote machine:
Next, I specify the python interpreter to be used for my project. I go to File | Settings (Preferences for Mac OS) | Project | Project Interpreter. By default, PyCharm sets the local Python interpreter as a project interpreter, so I’ll change it to the remote one:
As I’ve already created a deployment configuration, PyCharm offers to export Python interpreter settings from the existing deployment configuration:
But I can also specify the remote interpreter manually, using SSH credentials or a Vagrant configuration. Here I’ll do it manually:
After I specify the new remote python interpreter, PyCharm starts indexing and finds that the flask package is not installed on the project interpreter:
I can fix this easily with Alt + Enter on the unresolved reference error highlighted with red:
Alright. Now everything is ok, so we can finally specify Run/Debug configuration and launch our application. Let’s go to Run | Edit Configurations and add a new Python run/debug configuration:
In the Run/Debug configuration dialog, I specify the name for my new configuration and the script to be executed on the remote host. PyCharm sets the project interpreter (remote in this case) by default for this new run configuration, and finally I need to specify path mappings for this particular run configuration:
It seems we’re all set. I click the Run button:
PyCharm shows that the application is up and running on port 5000 on the VM.
I open the browser to check that the application is really working:
From this point on, we can work with this project like with a normal local project. PyCharm takes care of uploading any changes to the remote machine and keeps the VM up and running.
With the same Run/Debug configuration, we can do a simple remote debug session putting a few breakpoints right in the editor:
Click the debug button or go to Run | Debug:
That’s it! Hopefully you’ll appreciate this remote development functionality in PyCharm that makes Python remote development a breeze.
If you’re still craving for more details on PyCharm remote development capabilities, as well as other remote development features, please see the online help.
Talk to you next week,
Dmitry
Can’t wait for Docker support!
hi Iryna.
i did’t use it personally, but you can check out the plugin:
Docker support will be introduced in PyCharm starting with PyCharm 4.1 EAP (beginning of April)
What exactly will be supported? In my opinion remote debugging is the most important.
A lot of people asks about that. Of course this can be somehow done with dockerized ssh service, but this is terrible solution, since there is a docker exec, which I believe should be used for that, however I could not figure out how to configure it, to have this work.
Any news about that release?
PyCharm 4.5 is out, where’s the docker remote interpreter?
We planned to introduce docker support in the next release.
oh .. such a timely post. we just moving in to Vagrant setup.
From yesterday, i am struggling to figure out deploying Django project on Vagrant from Pycharm pro. But, Google yet not brought this post up. I just saw it on Reddit/r/Python.
i hope now i can code, and deploy happily ever after. Thanks Dmitry (y)
Thanks. In case of any problems with setting up Vagrant or anything else please feel free to contact our support: https://intellij-support.jetbrains.com/anonymous_requests/new
i successfully did the setup, thanks to your step-by-step procedure … (cheers)
Pingback: LUG дайджест #6 + Бонус | LUG Udmurtia
This features don’t available in PyCharm CE?
yes. Remote development functionality is available only in PyCharm Professional Edition. I’ll add a note to the blog post. You can find more info on differences between PyCharm PE and CE here: https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html
it’s helpful, thanks.
Here’s an idea. What if you take the time it took you to write this blog post and spend it to fix at least some of the numerous long-outstanding issues related to remote interpreter support. Such as refreshing installed packages, re-running tests, remote debugging, links from exception trace to actual code. It’s a feature we pay for, so if you want to boast about it, at least make it work.
Also, why do I need to manually map my remote libraries to the local ones that PyCharm copied? PyCharm copied them, it knows where they are, let it do the mapping.
A friendly reminder to the remote interpreter issues: https://youtrack.jetbrains.com/issues/PY?q=%23{Remote+Interpreters}+
You don’t need to map libraries but your project sources. First you map them on uploading (with the deployment tool) then you specify mappings for the particular run configurations as there might be several run/debug/test configurations with different mappings.
The fixes that you’ve mentioned are planned for PyCharm 4.1 (EAP comes soon)
For example this one: https://youtrack.jetbrains.com/issue/PY-13946 (refreshing installed packages). You can check the state of existing tickets in youtrack or file new problems found.
Sometimes writers aren’t also engineers. And blog posts take a lot less time than fixing bugs.
Still don’t available in PyCharm CE?
Here’s an idea. Thanks.
I wonder what password did you enter for user vagrant. Did you use the ssh key? if yes, where can i find it?
Normally the password is “vagrant”
Pingback: Feature Spotlight: Editing remote files | JetBrains PyCharm Blog
Here’s an idea. Thanks.
Very useful information, thank you!
This is great thanks! I am trying to get this to work in the context of WSGI and it doesn’t seem to work. Any tips?
please contact technical support at https://intellij-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66731
We’ll be glad to help.
Hi,
First of all, thanks a lot for the information. I followed the tutorial but facing one issue. I am getting error as “PermissionError: [Errno 13] Permission denied” when I tried to run. But I was able to run the application by SSH login and running app.py with “sudo python app.py”. Is there any way to resolve this issue so that I can be able to run the application by clicking just run icon?
Any help would be appreciated.
could you please contact technical support https://intellij-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66731
describing the actual steps you did before you got the error? Is it a vagrant setup?
Having the same error when I tried to run, I’m contacting support now, will update if I still have any issues. Thanks Dmitry Filippov.
Pingback: Tpircsboy's Blog | 使用Pycharm进行Python远程开发
Hi Thanks for your kind post. I followed your instruction to deploy it. But there is log error:
I want my current local project directory blueprintexampe to be mapped to remote /home/vagrant/blueprintremote. Now I can right-click my project in the project view and select Upload to. But there is log error is shown as following:
Upload to 192.168.33.10 failed: SSH_MSG_DISCONNECT: 2 Too many
authentication failures for vagrant
Could you tell me how to solve it, please!
please contact jb.gg/pycharm-support . Please attach your log files Help | Find logs in files.
Thanks for the great post! I fumbled through on my own and figured out how to set up remote support, which has been very helpful, but I didn’t know about the automatic upload feature until reading this blog. I’m excited to try that in the morning. Clicking “Upload” every so often was getting a tad burdensome.
Excellent post. I used this to setup remote debugging on Vagrant using django with a virtualenv and a shared folder for the source. It’s quite magical when it steps through the remote code.
I’m glad you like it!
Hey, I’m a noob and started learning Python and followed your method and facing this error: PermissionError: [Errno 13] Permission denied, how can I fix it? Thanks in advance.
Hi please contact pycharm support jb.gg/pycharm-support and describe what are you trying to do.
Hey Dmitry, I just started the deployment process, I’m new to it and an upcoming Python lover :). I’ll update you about my installation, I something goes wrong I’ll come back. Thankyou
Hi Dmitry! How can I use remote python interpreter for multi-hop ssh connections (When I’m connection to machine B throw machine A)?
PyCharm doesn’t provide any support for setting up multi-hop connections. So all you can do is to specify the only one host when setting up your remote interpreter. The only workaround I can think of is to manually setup ssh tunneling on your intermediary machine and then specify its hostname in PyCharm. If you really want pycharm do this for you, please file a feature request to https://youtrack.jetbrains.com/issues/PY
This seems to be PyCharm only? IntelliJ Ultimate with Python Plugin doesn’t work?
Just starting out with remote Python development, and this helped me get my head around using PyCharm.
Keep up the good work!
Newbie here!! Still trying to understand
Hi, Thank you for the wonderful post. I have quite successfully set up the pycharm for remote usage. However on one my office PC I cannot run through pycharm as it requires double hop. Could you kindly give me some help on how can I do the double hop on pycharm? I checked the solution on this thread but I do not quite understand. I think it does not provide full commands.
Thank you for your time.
Hi Isabella! Unfortunately, we don’t support bastion hosts directly in PyCharm at the moment. If you’d like to connect to this computer, you’d need to run an SSH command to open an SSH tunnel to your destination host, and then tell PyCharm to connect to localhost:
Run
ssh -f user@your-first-hop -L 2000:your-second-hop:22 -N
on the command line. And then connect PyCharm to localhost:2000, using the username and password or key for your second host.works for men. thanks
What “PermissionError: [Errno 13]” means? Thanks Let me know
Have a look here: https://stackoverflow.com/questions/13207450/permissionerror-errno-13-in-python
Pingback: 使用Pycharm进行Python远程开发 | 数码淘
Here’s an idea. What if you take the time it took you to write this blog post and spend it to fix at least some of the numerous long-outstanding issues related to remote interpreter support. Such as refreshing installed packages, re-running tests, remote debugging, links from exception trace to actual code. It’s a feature we pay for, so if you want to boast about it, at least make it work.
Pingback: Pycharm Remote Deployment | Pycharm 远程部署设置 – Neurohazard
Hi, Thank you for the wonderful post. I have quite successfully set up the pycharm for remote usage. However on one my office PC I cannot run through pycharm as it requires double hop.
We actually support bastion hosts in newer versions of PyCharm. See the ‘Setting up PyCharm’ part of this blog post to learn how: https://blog.jetbrains.com/pycharm/2017/12/creating-a-development-environment-on-amazon-ec2/