Set PyCharm python interpreter based on my already existing docker container python environment

I'm trying to set up PyCharm's python interpreter so that it uses the python environment that's already set up on docker.  I have my docker containers environment already set up and running, totally separate from PyCharm.  I'm using docker desktop on my mac.  And I'm developing on PyCharm.  Historically I'd configure PyCharm's python interpreter using my virualenv I manually set up, but now that I'm using docker I'd like to have Pycharm just refer to the one that's already created using docker desktop via:

`docker-compose build`
and
`docker compose -f dev.yml run --entrypoint bash namegoeshere`

When I follow the guides on PyCharm's website for docker and docker compose, they seem to create new containers that are totally separate from my containers that already exist.  And then my python interpreter shows either an empty to newly initialized list of python packages.  I don't want pycharm to create a new one, I just want to refer to the one that's already in existance in my container.  Is that possible?  

Guides I've been following:

https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html#config-docker

https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html

I tried following the docker compose tutorial, and selecting my .yml file and then selecting the container name I want to target, but it still creates a brand new environment rather than using that container that's already running. Is there any way to select the one that's already running?


Screenshots of what it ends up looking like after I follow these guides:



Created using Add new interpreter -> docker compose, notice it's blank and not using my container's packages



An example of Pycharm creating a totally separate container, rather than using the one that's already created



An example where it created a blank/initialized set of packages, instead of using my already existing container. 

 

1 comment
Comment actions Permalink

Hello, 

Yes, I confirm a new container is being created every time you run/debug code. There is no native support to use interpreters in s running container. 

The only possible workaround, which is a tricky one, is to use the existing container is to configure an SSH based interpreter https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html#ssh-credentials , but please note that the Deployment configuration will be also created, which will copy all project files to the container and will constantly keep them synched. 

0

Please sign in to leave a comment.