Setup PyCharm to use a Project Interpreter in a Docker Compose Service
Mar 23, 2019Overview
If you are anything like me, you heavily rely on a debugger. Likewise, you install all your development environments into a docker container because installing things on your own computer is FOR THE BIRDS. I cannot tell you what a relief it is to have all my development environments safely in docker containers. I break operating systems frequently. It's a serious problem for me and I needed an intervention. For me, this intervention was docker. I do not care how often I break a docker container, because 1. it's versioned, and 2. I can always just rebuilt it. MAGICAL.
The Problem
Many IDEs and editors assume you are working from a local environment. I think this is changing with so many people moving towards cloud computing and technologies like docker. I don't have an exact list of IDEs that do and do not have use an interpreter from a docker or docker-compose environment.
The Solution (Well, a solutions anyways! )
The JetBrains IDEs support a whole host of execute code somewhere besides your computer. I've been using the JetBrains IDEs, namely PyCharm and WebStorm, and occasionally one of the others when I am supporting a researcher in some other language. I really love them, namely because of their debuggers, which are amazing, the fact that you can increase the memory the IDE can use for intensive applications, such as data science applications, and they several 'setup your interpreter to be someplace else' options. I only care about Docker and SSH, but if you use Vagrant they have that too. The only downside is that they are paid, but I feel that they absolutely save me enough time to justify the price tag. Time is money!
Quick disclaimer, no I am not being paid to talk about JetBrains IDEs. I just think they are an extremely high quality set of tools. Again, I think other IDEs may have this same functionality, but I use PyCharm so there we go.
SetUp PyCharm for Docker-Compose
PyCharm works by having separate projects. Each project has an interpreter, which has its associated python packages. If you need to step through the code of any of these libraries than of course you can, in addition to running tests from any of these libraries.
Add the Project Interpreter from Docker-Compose
Whenever I need to search for anything in PyCharm, either functionality of the IDE itself, class definitions, or tests, I simply double press Shift. This brings up a search menu and is by FAR the easiest way to navigate the menus. I actually find the menus themselves a bit confusing, but that search box is great.
So, double press Shift to bring up the search menu, and start typing 'Project Interpreter'. You probably won't even need to type the whole thing to get the correct menu option.