To use PyCharm's interactive console with the local development environment you need to do some basic manual configuration.

Note: this document is for users of the older Docker Toolbox/VirtualBox set-up.

If you are using the native Docker for Mac or Docker for Windows applications rather than Docker Toolbox and VirtualBox, see our Set up local development environment with Docker for Mac/Docker for Windows and PyCharm document instead.

Requirements

  • Divio Shell (Mac or Linux
  • PyCharm Professional edition (please ensure your version is up-to-date)

Initial PyCharm Setup

Note: depending on the theme you're using with PyCharm, the appearance of the dialogs below may be different, but the functionality will be the same.

  1. Open PyCharm
  2. Open the Settings/Preferences 
  3. Search for Docker in Build, Execution, Deployment
  4. Select Docker and press the "+" icon (this sets up Docker automatically with the correct settings). Please note that your file path will be different from the one shown below. 
  5. Apply the changes.

Project Setup

First, Setup the project locally with Divio. 

Associate the project with its docker-compose file

  1. In PyCharm, open the project in the usual way.
  2. Back in PyCharm's Settings/Preferences dialog, search for Project Interpreter and select it.
  3. Click on the settings icon on the right and select Add Remote.
  4. Select Docker Compose. This will configure the appropriate settings. Please note that your file path will be different from the one shown below. The only change you need to make is to select web rather than db in the Service name field:

You'll notice that it has automatically discovered your docker-compose.yml file and the services listed in it.

Edit the Run/Debug configuration

Select Edit configurations for your project.

Set the host and port:

  • host: 0.0.0.0
  • port: 80

Run the project

Hit the Run button (or control-r) to launch the site locally:

This runs docker-compose up on the project. 

In the Divio App, you'll now see that the project is running (you may need to refresh the view to see it).

If you don't know the IP address of your Docker machine, docker-machine ip will tell you. Visit this in your browser on port 8000, and you'll see your project.

Make the most of PyCharm

PyCharm is a hugely powerful IDE, with a vast range of features, and offers a great deal of control and insight into your projects:

It's worth exploring to find out more about how it can help you in your Divio CLoud development work.

Note: not all of these features are available when using Docker - for example, debugging tools will not work.

Tip: If you're using PyCharm on Ubuntu, this link might help you with some common issues: Enable Remote API on Docker hosts running systemd (like Ubuntu 15.04).

Did this answer your question?