繁体   English   中英

附加到 Docker 容器的 vscode - 找不到模块

[英]vscode attached to Docker container - module not found

我在Docker容器内运行vscode调试器,但它开始显示错误: 在此处输入图像描述

这很奇怪,因为当我在同一个 vscode window 中打开vscode shell 并导入相同的模块时,导入工作正常。 所以我需要找到调试器看不到模块的原因

完整的错误代码:

root@854c8a51d1f6:/opt/HonkioServer# python3 entrypoints/api2/docker_entry 
Traceback (most recent call last):
  File "entrypoints/api2/docker_entry", line 3, in <module>
    from index import app
  File "/opt/HonkioServer/entrypoints/api2/index.py", line 9, in <module>
    from honkio.db.Application import ApplicationModel
ModuleNotFoundError: No module named 'honkio'
root@854c8a51d1f6:/opt/HonkioServer#  cd /opt/HonkioServer ; /usr/bin/env /bin/python3 /root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 39239 -- /opt/HonkioServer/entrypoints/api2/docker_entry 
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/opt/HonkioServer/entrypoints/api2/docker_entry", line 3, in <module>
    from index import app
  File "/opt/HonkioServer/entrypoints/api2/index.py", line 9, in <module>
    from honkio.db.Application import ApplicationModel
ModuleNotFoundError: No module named 'honkio'

我的调试器配置文件launch.json

    {
      "name": "Python: File",
      "type": "python",
      "request": "launch",
      "program": "/opt/HonkioServer/entrypoints/api2/docker_entry",
      "justMyCode": true
    }

最后我找到了这个问题的根源 - 它在直接导入到docker-entry文件的文件中,并且项目目录中的模块以一种奇怪的方式导入:

# This line adds to modules imports that added below cd two levels up
sys.path.insert(0, os.path.dirname(__file__) + "/../..")

import honkio

但是,在我在vs code中更改此文件后,格式化程序自动更改了行顺序,将该行放在所有其他导入的底部。 因此文件导入中断并显示module not found error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM