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?
-
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?David Maze– David Maze2021-03-25 21:28:49 +00:00Commented 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.FreeMind– FreeMind2021-03-25 21:36:26 +00:00Commented Mar 25, 2021 at 21:36
-
1I 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.Faeeria– Faeeria2021-03-25 22:11:34 +00:00Commented Mar 25, 2021 at 22:11
-
1Well, 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)Faeeria– Faeeria2021-03-25 22:17:55 +00:00Commented Mar 25, 2021 at 22:17
-
1I personnally would use it as an execution environment and consult the logs, but that also works.Faeeria– Faeeria2021-03-25 22:27:21 +00:00Commented Mar 25, 2021 at 22:27
1 Answer
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.