4

I have latest PyCharm installed. I have a docker container and I want to use its python interpreter as my project interpreter. Note that I don't want PyCharm to create new container from image every time I run my script. What are the steps to do so? If I use container interpreter will PyCharm support code completion for the packages installed in containers interpreter?

12
  • Why not just use your host's Python, maybe with a virtual environment for package isolation? What's wrong with creating a new container every time you run the script? Commented Mar 25, 2021 at 21:28
  • @DavidMaze The container is bundled with ready to use packages. In addition, my host is Windows and the software does not support Windows. Commented Mar 25, 2021 at 21:36
  • 1
    I understand. But that is not possible inside Pycharm. Unless you use Docker compose in Pycharm. Docker compose will stop and restart the containers, not delete and rebuild them. Commented Mar 25, 2021 at 22:11
  • 1
    Well, first of all : do you really want docker as an interpreter, or would it be okay to use it as an execution environment ? (that seems closer to your use case) Commented Mar 25, 2021 at 22:17
  • 1
    I personnally would use it as an execution environment and consult the logs, but that also works. Commented Mar 25, 2021 at 22:27

1 Answer 1

4

I've submitted a feature request on https://youtrack.jetbrains.com/issue/PY-53854 because this is simply not a feature in PyCharm.

One temporary solution I considered was to ask PyCharm to use the python from the Dockerfile: docker exec -it container-name python, but PyCharm unfortunately doesn't let me set a "command" as a python interpreter for the IDE. It does allow you to set the command for specific run/debug configurations though - so you could use the python interpreter in a running container if you don't want integration with the editor (e.g. import suggestions).


User: Is there a technical reason as to why PyCharm cannot use an interpreter inside an already running container? Or could I expect it to be part of a future release? It would be a very nice feature to have

Jetbrains team: I am not aware of any technical reasons. I couldn't find any feature request for it.

Please feel free to submit a feature request about it to our issue tracker using the link https://youtrack.jetbrains.com/issues/PY and let us know if you need any help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.