How to connect PyCharm to a python interpreter located inside a Docker container?

前端 未结 10 2197
再見小時候
再見小時候 2021-01-30 03:40

I\'m starting with Docker, but I don\'t know how to configure PyCharm to use a python interpreter located in a container.

It was easy to setup with Vagrant, but there\'s

10条回答
  •  余生分开走
    2021-01-30 04:04

    In order to avoid any SSH overhead (which makes perfect sense with Docker), docker exec definitely seems to be the way to go.
    Unfortunately I couldn't get it to work so far. It would be great if someone could fill in the blanks. Here is what I did (using PyCharm 4.0.4 and Docker 1.4.1):

    1. Create a file named python_myproject.sh containing the following:

      #!/bin/bash
      docker exec -i myproject_container /path/to/containers/python2.7
      

      Note that the file's name has to begin with python otherwise PyCharm will complain.

    2. In PyCharm's settings, under Project Interpreter, add a new local interpreter. Give it the path to your python_myproject.sh file.


    This is where I'm stuck. After a quite long loading time (the throbber says "Setting up library files"), a window entitled "Invalid Python SDK" appears and says:

    Cannot set up a python SDK
    at /path/to/python_myproject.sh.
    The SDK seems invalid.

    In ~/.PyCharm40/system/log/.idea:

    2015-02-19 17:33:30,569 [ 166966]   WARN - ution.process.OSProcessHandler - Cannot kill process tree. Trying to destroy process using Java API. Cmdline:
    2015-02-19 17:34:30,628 [ 227025]   WARN - ution.process.OSProcessHandler - Cannot kill process tree. Trying to destroy process using Java API. Cmdline:
    2015-02-19 17:34:30,653 [ 227050]   INFO - rains.python.sdk.PythonSdkType - 
    Timed out
    

提交回复
热议问题