Working with python , poetry and docker in Pycharm

Working with python , poetry and docker in Pycharm

I have to say that I really really love working with  the jetbrains products, they are so beautiful , it doesn’t matter what IDE  you do choose , they all are pretty fabulous 

Right now I'm working with Pycharm, and it’s fantastic (as also PHPStorm and WebStorm are) . The workflow , the tools  to work with databases, tests , debugging , and running applications inside docker containers are simply amazing.

This time I want to share with you a little tip that  maybe can be helpful and save you some time and headaches.

If you are working with python and poetry running on docker with a docker-compose file, and you’re having some troubles with the autocompletion, because the editor does not recognize your installed libraries, the cause might be that your IDE isn’t recognize the python interpreter running within the container,  so you have to configure it.

To do that , you will have to follow the next steps:

  • First start the docker container where your python app with poetry will be running and attach a new terminal to the running container
  • execute  poetry env info   command 
  • that command will show us the next information 

Article content

  • Copy and save the Executable path. We will use that information later cause  it's where the python interpreter we want to use is located inside our container 
  • Next , go to  Preferences > Python Interpreter 

Article content

  • Once you are there , the next step is click to  “Add interpreter”  and  then click   “On docker-compose

Article content


  • Then , in the next window we will need to provide some parameters:- server: which have to be a  Docker server- configurations file:  the docker-compose yaml of your project- service: from where your docker container running python and poetry will be started

Article content


  • click next,  then the IDE will create and configure our new docker-compose target

Article content

  • Once the IDE has finished click next 
  • In the next window select the tab Virtual Environment 

Article content

  • click the button with the icon (...) , and it will show us a new window where we will need to paste the path to the python interpreter  that we copied earlier 

Article content


  • click Ok
  • select the path from the options and click on Create  button 

Article content


  • And it’s done , now our selected python interpreted should show us all python packages installed in our container 

Article content

Now you can go to the editor and the autocomplete should be working as fine as always

As you can see, working with docker using IDEs from jetbrains is so easy 


Note: if you don't have any project to work with and follow these steps , you can take the project from this repo. It will help you to play throughout the steps.


I hope this tip can help to you.

Hello, I have a question below help me How can i install libraries in pycharm once and use it in all projects? I have searched everywhere i am not getting specific solutions please give me step by step guidance on this Thank you

Like
Reply

To view or add a comment, sign in

More articles by Ariel Santos

Others also viewed

Explore content categories