Have you ever wanted to develop a Python or Web application for Linux from your laptop running Windows 7 or MAC OS X? To debug or test your application on different operating systems without ever leaving the IDE? Or just to run large applications that you develop as a team on a dedicated provisioned environment, rather than on regular workstations? Guess what: all of this is possible with the remote development features already available in PyCharm.
The central entry point to remote development with PyCharm is the notion of Remote Interpreters.
You can configure PyCharm to use Python interpreter from a remote host and set it as your project interpreter. Then you can configure your run/debug configurations to run, debug or test your applications on the remote host. The remote host can be a physical remote server, a VM or even a virtualenv environment – it doesn’t matter. PyCharm has everything you need to work with all types of remote hosts.
Actually, most of the Remote Development stuff was already available in previous versions of PyCharm and covered in these nice tutorials. But we never stop working on improving your comfort and user experience, so PyCharm 2.7 gets new additional features.
Vagrant integration
Native Vagrant integration is now implemented in PyCharm 2.7+. It is supported via the plugin Vagrant that comes already bundled with PyCharm. Vagrant integration makes it much easier to provision and manage your VMs, connect to them over the SSH and automatically configure a remote interpreter and an FTP deployment, if you run your development environment in a VM using Vagrant. All this without leaving the IDE!
Before you start working with Vagrant, make sure that the Vagrant plugin is enabled (this is the default). Also make sure that Oracle VirtualBox and Vagrant are installed on your machine.
First, open Settings | Project Settings | Vagrant:
Enter appropriate paths for “Vagrant executable” and “Instance folder,” and then add your first Vagrant Box by clicking the Add (green plus) button:
Here, choose a name for your new Vagrant box and provide the Box URL for downloading the template. Click OK to start downloading your VM.
Good! Now, after this step we have VM downloaded and added to our environment:
Next, open Tools | Vagrant. You will see the Vagrant menu node containing different commands, which correspond to the standard Vagrant actions:
First you need to initialize a Vagrantfile for your project. Select “Init in Project Root” in the menu to automatically create the Vagrantfile, and you will be able to see and modify it like any other file within your project.
Now you can start your first VM! To do so, select Tools | Vagrant | Up.
On the bottom of the screen a special console will open showing you the progress and output from Vagrant:
To be able to run your project on the VM or to connect to the VM, you need to configure the remote interpreter.
This is done through Settings | Project Settings | Project Interpreter | Python Interpreters. Click the Add button and select “Remote interpreter.” Here you will get the “Configure Remote Python Interpreter” dialog:
You can fill it manually, as for an arbitrary remote host, or just use “Fill from Vagrant config.” Click it – and voila! All the required fields are filled with your Vagrant box details.
After this step the remote interpreter will be added to your project. You can set it as the default project interpreter as well.
From this point on you can execute your project using the remote interpreter on the VM:
The Vagrant plugin works gracefully with the Vagrantfile. You can manually edit it, and all you need is just to click Tools | Vagrant | Reload for the Vagrant plugin to pick up new settings.
For example you can set up custom path mappings in Vagrantfile:
After the Vagrant Box is reloaded, a mapping will be created and you will see a new shared folder into your project folder.
Integrated SSH console
One of the coolest and most useful features is that you can log in to your remote host via SSH and work in its console without leaving PyCharm. To do that, just select Tools | Run SSH Terminal. A console opens on the bottom with the prompt:
Feel free to discover its usability. You can even launch Vim in it:
As you can see, PyCharm comes with everything but the kitchen sink! So we really hope you’ll enjoy these new enhancements and feel comfortable developing your applications on remote environments. And as always, please report your issues or feature requests to our YouTrack bug-tracker.
Develop with Pleasure!
PyCharm team
Could vagrant box be started automatically when I open PyCharm project using it?
Right now I open my project and PyCharm complains that it cannot connect to remote interpreter.
Hi! Not yet, but that is planned to be in the next version http://youtrack.jetbrains.com/issue/PY-8751
I wonder if this actually made it in to v.3.0? The issue doesn’t seem to have any activity on it, and I’m getting the same error mentioned in the original post. Update? Thanks
Not implemented yet. Will ping someone to fix it.
This works with PyCharm 3.4.1
After opening the project PyCharm asks you whether you want to start the project’s Vagrant box.
now it would also be nice to have it halt when i close pycharm… :/
If you want Vagrant support in PhpStorm vote for the issue here:
http://youtrack.jetbrains.com/issue/WI-15874
Does PyCharm include auto completes for JavaScript ?
It does.
Too bad the console is still unable to intercept CTRL+C and the like…
try CTRL+SHIFT+C
FWIW remote development (and debugging) is the killer feature for me, and the main reason I am lobbying my boss to buy a commercial license and will buy a personal one myself if he says no. The way it figures out what libraries are installed remotely and installs its own helper code is very slick.
However, couple of things I’m struggling with:
Tools : Run Python Console does not seem to set up the path correctly (it uses the local path, not the remote one). And the Traceback after a run is not highlighted with links as I would expect. Possibly this is because the remote file paths are not recognised. Am I missing some trick?
Rob, could you please file YouTrack issues at http://youtrack.jetbrains.com/ for the problems you’ve encountered? Thanks!
Was this filed or fixed? I’m having the same issue.
Please file the issue to http://youtrack.jetbrains.com/issues/PY and attach system logs as shown here https://intellij-support.jetbrains.com/entries/23352446
There, it is supposedly fixed. Are you going to integrate it?
https://youtrack.jetbrains.com/issue/PY-10224
Can we get syntax highlighting for Vagrantfile in PyCharm? Or do we have to get IntelliJ or RubyMine to be able to edit these files without headaches?
Right now I feel like I’ll be better off editing in an external application, which seems weird when you’ve gone through all the trouble of integrating Vagrant in the first place.
Don’t misunderstand me, I love PyCharm.
Vagrantfile is a Ruby file, so it would be difficult for us to provide syntax highlighting for Vagrantfile without providing general Ruby syntax highlighting. And we have obvious business reasons for not including Ruby support in a Python IDE.
One possible option is to install a TextMate bundle for Ruby and to use it for highlighting the Vagrantfile.
I have managed to get syntax highlighting for Ruby files working with TextMate plugin, but no luck with Vagrantfile. No matter what I write into File Types (or into filetypes in TM-plugins plists’). Because Vagrant-support is a major features, syntax highlight for Vagrantfiles should be easier…
Although sort of a hack, the problem is that the Vagrantfile is not recognized as a ruby file. You could place a Vagrantfile.rb symlink to the Vagrantfile and edit that one, that would make PyCharm recognize the file as a ruby file and apply syntax highlighting accordingly.
Hey, there is another less hacky way of highlighting Vagrantfile please read this tutorial first: http://confluence.jetbrains.com/display/PYH/TextMate+Bundles+in+PyCharm
You might figure out that it is possible to specify Vagrantfile as template (instead wildcard) for ruby bundle to highlight Vagrantfile
It’s time for _next_pyCharm_version_ roadmap! )))
Yeah, it will be available soon)
Hey all,
I’m new to this and this and all of this looks very interesting, but my final goal with all this is to have a following set up:
1. Pycharm on my windows box
2. Fire up Vagrant with python, postgresql and django inside my project
3. Do remote debugging of my vagrant box through my pycharm by clicking debug. I think all the pieces are here, but i can’t seem to connect the dots. The goal is to not have minimum python-related stuff on my windows box but still be able to do editing through pycharm.
I am a bit frustrated (but also optimistic) that every time I come back to the topic of getting a remote interpreter fully working with PyCharm–that I can never actually close the loop.
First off–I am looking to get this working simply from PyCharm on Windows 7 connecting to a remote interpreter on an Ubuntu VirtualBox guest. I am NOT looking to use Vagrant (though every tutorial seems to imply this step) and simply want to connect to an existing VM that I run with full GUI. The connection test always works out, but when it comes to running the tests or project it can never find the settings or some such thing.
This configuration is important to me as it would open up what I am actually capable of doing in PyCharm. I don’t get if I need to do something with Servers–it seems configuring the remote interpreter lets you specify all the connection settings just fine.
Also I don’t get Where the code loads from — does it run off the location in Windows or does it run off what is in the VM? Kind of a trick question since I use Virtual Box shared folders already and they are actually the same location. Please Help!
You need to move your code to the directory in your VM that is the same as the local directory of where your code is, or a symlink.
Also you will need to copy the files from .pycharm_helpers to /home/vagrant/.pycham_helpers.
You will see a string of the command that PyCharm in running in the run dialog like this:
ssh://vagrant@172.16.1.90:22/usr/bin/python -u /Local/Path/To/MyCode/manage.py runserver 8000
Where local path to my code is where you code live on your machine. Make a symlink to that dir on your VM and you should be good to go.
Looks like I was wrong. os.getcwd() shows that the directory is /home/vagrant/ so putting your code there will work. Still looking into how to append the sys.path using a remote interpreter.
Is it possible to use an existing Oracle VM virtual box with vagrant, or only this lucid32 box? I am running windows at home and would like to use my debian virtualbox as remote interpreter. Currently I have this working through by ssh’ing to my virtualbox. This does work fine although I run into problems when I use matplotlib and want to get a graph as output – I get an error from Tkinter: no display name and no $DISPLAY environment variable.
How can I setup pycharm to work with my debian virtualbox and is it possible to get graphical output back?
Hey,
please check http://confluence.jetbrains.com/display/PYH/Configuring+Interpreters+with+PyCharm#ConfiguringInterpreterswithPyCharm-RemoteinterpreterviaSSH
Thus you’ll configure PyCharm to run/debug your project automatically on your existing virtualbox machine. It works through SSH internally, so there will be the same problem of getting any graphics as an output. In your case you need to use some remote desktop software to see graphics.
Hi,
Vagrant support is great but there’s little thing that bugs me. Before using vagrant, error traceback produced by python shows local file path that when you click on it, pycharm brings it on editor. This is very convenient. But when using vagrant the traceback shows remote path which pycharm cannot link to.
Image: http://cl.ly/image/0x1Z3n3z2a2c
Any chance getting around this ?
Thank you
+1
This makes the remote interpreter pretty useless.
Is it possible to launch a Django app in vagrant and set breakpoints in pycharm? I have been able to <i<run my Django app using the run configuration with my vagrant python interpreter, but when I try to use the same config to debug it it fails (I browse to my application in the browser and nothing is running). Is there some additional setup required to make this possible?
Q: Is it possible to launch a Django app in vagrant and set breakpoints in pycharm?
A: Yes sure. Vagrant is just VM provisioning tool.. nothing more. PyCharm treats VM as a remote host. And our debugger works remotely.
I suggest you to look through bugs http://youtrack.jetbrains.com/dashboard/PY
or go to our forum and let us know the details. http://forum.jetbrains.com/forum/PyCharm
Is there a tutorial which walks me through setting up Virtual Environment for Django App with Vagrant and then configuring PyCharm remote debugging to work with it.
well, we have separate tutorials covering different parts of your case, however no one big walk-through tutorial on django/venv/vagrant/remote-debugging. However we try to update out tutorials collection at http://confluence.jetbrains.com/display/PYH/Tutorials
and
http://www.jetbrains.com/pycharm/quickstart/django_guide.html
you also can find info on configuring virtual environment in PyCharm help.
Can you guys add a Vagrant command for “provision?” I’m working a lot on my Puppet modules and having a keyboard shortcut for provisioning my box would be AWESOME.
Hey, please vote here:
http://youtrack.jetbrains.com/issue/PY-9869
Hi,
Is there a way to connect Pycharm (edit files, debug) to an existing vagrant setup on VM?
I believe there is a way to do so. However we need to know what exactly do you mean? “vagrant setup on VM” do you mean to connect PyCharm to already existing Vagrant instance?
Hi,
Thanks for the tutorial, it works great. My only concern now is on how to be able to debug on my vagrant box…
Do I have to map my local source folders with those in the box? If so…how?
Do I have to setup a Remote Debug server like what’s explained here: http://www.jetbrains.com/pycharm/webhelp/remote-debugging.html
To me it looks like the first scenario: Remote Debugger with a remote interpreter.
Thanks!
Alejandro,
you’re right it’s more like the first scenario – remote debugger with a remote interpreter. But, there’re some things that vagrant already does for you. For example it maps you’re current folder (project root) to the VM home folder (check the vagrant config that appears after init in the project root).
Thanks for the excellent write-up, I was searching for details like this, visiting visit the other articles.
We’re a web agency and we do our projects with Vagrant and PyCharm. To speed up bringing new developers on a project we generate a default PyCharm configuration (Django, runservers i.e. RunManagers, SSH Terminal, JIRA integration, database browser). That works pretty well, but the major headache is still Vagrant:
– Is there a way to set up the Project Interpreter for a Vagrant box with the configuration files, and/or from the command line (before starting PyCharm)?
At the moment, we still need to configure the Project Interpreter manually after starting PyCharm for the first time for a project. PyCharm loads a couple of helpers onto the Vagrant box. If that is all and does the trick, can that be triggered from the command line or so?
Hi, Peter,
the command-line or config based configuration is not supported yet, manual configuration is still required. Could you please submit and issue to our tracker https://youtrack.jetbrains.com/issues/PY and we’ll hot to fix this.
I’ve added https://youtrack.jetbrains.com/issue/PY-15253
Can you share some details in the meantime about where the helper scripts are that PyCharm uploads to the Vagrant box? (copy source and copy target)
Any news on this?
Can you share some details in the meantime about where the helper scripts are that PyCharm uploads to the Vagrant box? So we could copy them “manually” (via a script) from PyCharm’s location to the target folder on the Vagrant box.
Pingback: Feature Spotlight: Python remote development with PyCharm | JetBrains PyCharm Blog
Pingback: PyCharm 프로젝트 설정문드립니다. local에 파일을 두지 않고, 원격 서버에 붙어서 | fb.com/groups/django/
Pingback: 使用Open edX中国社区Docker版来开发调试edX | 三更灯火五更鸡
Is there any way to improve pycharms console output buffering?
I don’t see any console output until a test has finished.
If I kill a test at 99% completion, there’s no output.