没有让PyCharm在docker上使用远程解释器

时间:2018-04-13 13:33:27

标签: docker pycharm docker-compose

当我从我的docker-compose之一添加远程解释器时,它似乎没有成功,也没有在对话框中显示任何包。当我向调试器添加解释器时,它说:

python packaging tools not found.

然后,如果我点击安装包装工具,则显示错误:

ERROR: for dockeryard_pycharm_helpers_1
Cannot start service pycharm_helpers: network not found

Starting dockeryard_postgres_1 ...  
Starting dockeryard_nginx_1    ...  
Starting dockeryard_redis_1    ... 
Starting dockeryard_postgres_1 ... 
Starting dockeryard_nginx_1 ...  
Starting dockeryard_pycharm_helpers_1  
Starting dockeryard_redis_1  
Starting dockeryard_worker_1 ... 
Starting dockeryard_worker_1
Starting dockeryard_pycharm_helpers_1
ERROR: for dockeryard_pycharm_helpers_1  Cannot start service     pycharm_helpers: network not found

ERROR: for pycharm_helpers  Cannot start service pycharm_helpers: network not found
[31m  
ERROR [0m: 

注意,这个解释器已经在使用,我可以远程连接PyCharm,但我已经添加并最终将自定义网络移除到容器中。

Configuring Remote Python Interpreters中所述 - “当添加远程Python解释器时,首先将PyCharm助手复制到远程主机”。我的猜测出现了问题,因为网络在docker-compose中更新了。

根据我从错误消息中的理解,当PyCharm启动解释器时,它会尝试使用/找到该网络c7b0cc277c94ba5f58f6e72dcbab1ba24794e72422e839a83ea6102d08c40452

我在运行时看不到任何地方列出的网络:

$ docker network inspect dockeryard_default

所以PyCharm将它存储在某个地方并且没有更新。 我试图删除解释器(使用PyCharm对话框)并将其添加回来 - 结果相同。

如何摆脱这个网络并使PyCharm能够再次调试?

感谢。

4 个答案:

答案 0 :(得分:19)

有一个几乎相同的错误,并能够通过它。我做了两件事,虽然我不确定哪个是实际的解决方案:

  1. 确保(a)Preferences -> Project -> Project Interpreter -> Path mappings和(b)Run -> Edit Configurations -> <Your_Configuration> -> Path mappings
  2. 下的映射都是正确的
  3. 删除/删除任何看起来与PyCharm相关的容器(相信这很可能解决了问题)。
  4. 希望这会有所帮助。 PyCharm docker-compose似乎对某些人有用,对其他人来说是真正的PITA。

    另一个注意事项。我从2018年的PyCharm降级到2017.3,因为2018年已经发现了码头虫。

    编辑:看来来自CLI的docker-compose down重新引入了错误-_-

答案 1 :(得分:2)

选项 invalidate cache -> Clear downloaded shared indexes 也将重新填充 Pycharm 卷。 (至少在 2021.1)

答案 2 :(得分:1)

如果您仍在PyCharm 2020.2中看到此内容,请执行以下操作:

  • 关闭PyCharm
  • 尝试@peterc的建议:
docker ps -a | grep -i pycharm | awk '{print $1}' | xargs docker rm
  • 再次启动PyCharm

答案 3 :(得分:0)

TLDR:

{project_name}_pycharm_helpers_{pycharm_build_number}卷已被删除或已损坏。

要重新填充,请运行:

docker volume rm {project_name}_pycharm_helpers_{pycharm_build_number}
docker run -v {project_name}_pycharm_helpers_{pycharm_build_number}:/opt/.pycharm_helpers pycharm_helpers:{pycharm_build_number}

可以在pycharm的“关于”部分找到pycharm_build_number(Mac OS:Pycharm>关于)

长话

我与PyCharm进行了很多斗争,突然间找不到更多帮助程序或任何相关的错误,有时是因为我正在清理容器或卷。例如,运行

docker rm -f `docker container ps -aq`
docker volume rm $(docker volume ls -q)

几乎肯定会使pycharm陷入麻烦。

有关PyCharm的工作原理的文章有:

  • 名为pycharm_helpers的PyCharm基本映像,其标签与您的pycharm内部版本号相对应(例如:PY-202.7660.27)
  • 第一次创建与Docker相关的东西时,PyCharm创建volumes,该图片从该映像中获取数据以供以后在容器中使用。例如,在第一次尝试运行远程docker-compose解释器后,我在执行myproject_pycharm_helpers_PY-202.7660.27时看到了新创建的docker volume ls卷。
  • 运行docker解释器时,PyCharm会在某个时候向命令中添加/opt/.pycharm_helpers来将此卷添加到-v cal-toolkit_pycharm_helpers_PY-202.7660.27:/opt/.pycharm_helpers目录中。例如,使用docker-compose,您可以看到-f /Users/clementwalter/Library/Caches/JetBrains/PyCharm2020.2/tmp/docker-compose.override.1508.yml的添加,当您实际查看此文件时,您会看到:
version: "3.8"
services:
  local:
    command:
    - "python"
    - "/opt/.pycharm_helpers/pydev/pydevconsole.py"
    - "--mode=server"
    - "--port=55824"
    entrypoint: ""
    environment:
      PYCHARM_MATPLOTLIB_INTERACTIVE: "true"
      PYTHONPATH: "/opt/project:/opt/.pycharm_helpers/pycharm_matplotlib_backend:/opt/.pycharm_helpers/pycharm_display:/opt/.pycharm_helpers/third_party/thriftpy:/opt/.pycharm_helpers/pydev"
      PYTHONUNBUFFERED: "1"
      PYTHONIOENCODING: "UTF-8"
      PYCHARM_MATPLOTLIB_INDEX: "0"
      PYCHARM_HOSTED: "1"
      PYCHARM_DISPLAY_PORT: "63342"
      IPYTHONENABLE: "True"
    volumes:
    - "/Users/clementwalter/Documents/myproject:/opt/project:rw"
    - "pycharm_helpers_PY-202.7660.27:/opt/.pycharm_helpers"
    working_dir: "/opt/project"
volumes:
  pycharm_helpers_PY-202.7660.27: {}

如果此卷没有正确填充,您会遇到麻烦。 幸运的是,docker volume documentation包含“使用容器填充卷”部分,这正是PyCharm在后台执行的操作。

作为记录,您可以检查pycharm_helpers图像的内容:

$ docker run -it pycharm_helpers:PY-202.7660.27 sh
/opt/.pycharm_helpers #

您最终进入pycharm_helpers目录,并在此处找到所有帮助程序:

/opt/.pycharm_helpers # ls -la
total 5568
drwxr-xr-x   21 root     root          4096 Dec 17 16:38 .
drwxr-xr-x    1 root     root          4096 Dec 17 11:07 ..
-rw-r--r--    1 root     root           274 Dec 17 11:07 Dockerfile
drwxr-xr-x    5 root     root          4096 Dec 17 16:38 MathJax
-rw-r--r--    1 root     root          2526 Sep 16 11:14 check_all_test_suite.py
-rw-r--r--    1 root     root          3194 Sep 16 11:14 conda_packaging_tool.py
drwxr-xr-x    2 root     root          4096 Dec 17 16:38 coverage_runner
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 coveragepy
-rw-r--r--    1 root     root         11586 Sep 16 11:14 docstring_formatter.py
drwxr-xr-x    4 root     root          4096 Dec 17 16:38 epydoc
-rw-r--r--    1 root     root           519 Sep 16 11:14 extra_syspath.py
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 generator3
-rw-r--r--    1 root     root             8 Sep 16 11:14 icon-robots.txt
-rw-r--r--    1 root     root          3950 Sep 16 11:14 packaging_tool.py
-rw-r--r--    1 root     root       1490666 Sep 16 11:14 pip-20.1.1-py2.py3-none-any.whl
drwxr-xr-x    2 root     root          4096 Dec 17 16:38 pockets
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 profiler
-rw-r--r--    1 root     root           863 Sep 16 11:14 py2ipnb_converter.py
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 py2only
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 py3only
drwxr-xr-x    7 root     root          4096 Dec 17 16:38 pycharm
drwxr-xr-x    4 root     root          4096 Dec 17 16:38 pycharm_display
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 pycharm_matplotlib_backend
-rw-r--r--    1 root     root        103414 Sep 16 11:14 pycodestyle.py
drwxr-xr-x   24 root     root          4096 Dec 17 16:38 pydev
drwxr-xr-x    9 root     root          4096 Dec 17 16:38 python-skeletons
drwxr-xr-x    2 root     root          4096 Dec 17 16:38 rest_runners
-rw-r--r--    1 root     root        583493 Sep 16 11:14 setuptools-44.1.1-py2.py3-none-any.whl
-rw-r--r--    1 root     root         29664 Sep 16 11:14 six.py
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 sphinxcontrib
-rw-r--r--    1 root     root           128 Sep 16 11:14 syspath.py
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 third_party
drwxr-xr-x    3 root     root          4096 Dec 17 16:38 tools
drwxr-xr-x    5 root     root          4096 Dec 17 16:38 typeshed
-rw-r--r--    1 root     root       3354133 Sep 16 11:14 virtualenv-16.7.10-py2.py3-none-any.whl
  • 要使这些帮助程序再次可用,请遵循docker文档,您必须修复该卷。为此:
docker rm {project_name}_pycharm_helpers_{pycharm_build}
docker run -v {project_name}_pycharm_helpers_{pycharm_build}:"/opt/.pycharm_helpers" pycharm_helpers:{tag}

etvoilà