【问题标题】:I can't debug my script in vscode (mac) due to python path issues由于 python 路径问题,我无法在 vscode (mac) 中调试我的脚本
【发布时间】:2020-12-21 09:37:12
【问题描述】:

我完全是 python 和 vscode 的新手;我想开始学习语言。但是,我卡住了,我什至没有开始:D

在终端中,在 Python3 中,import sysprint(sys.executable) 我得到了在 vscode 的设置中复制粘贴所需的路径(即,使用 python.pythonpath 到 JSON 文件的简单附加行)。


(1) 但是,当我运行一个简单的打印脚本时,vscode 中的终端会显示“默认的交互式 shell 现在是 zsh。要更新您的帐户以使用 zsh,请运行 chsh -s /bin/zsh。 更多详细信息,请访问..." 并要求输入密码。当我输入密码时,我收到一个冗长的连接错误:

hsh: Credentials could not be verified, username or password is invalid.  Credentials could not be verified, username or password is invalid.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 95, in <module>
    main()
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 51, in main
    launcher.connect(host, port)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/__init__.py", line 34, in connect
    sock.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 95, in <module>
    main()
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 51, in main
    launcher.connect(host, port)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/__init__.py", line 34, in connect
    sock.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 95, in <module>
    main()
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 51, in main
    launcher.connect(host, port)
  File "/Users/xxx/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/__init__.py", line 34, in connect
    sock.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused.

我的名字是匿名的 xxx :)

(2) 当我尝试调试时出现以下错误:“调试配置中的 Python 路径无效。来源:Python(扩展)

这是 json 文件的样子:

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "tabnine.experimentalAutoImports": true,
    "python.pythonPath": "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"
}

知道如何克服这第一个大障碍吗?

非常感谢,

山姆

【问题讨论】:

  • 欢迎来到 SO。请格式化您的帖子以使其可读。编辑器中的“代码示例”按钮可能会有所帮助。

标签: pythonpath


【解决方案1】:

您的项目文件夹是否位于包含空格“”的路径中?当我使用的 venv 位于其中有空格的路径下时,我收到了同样的消息。当我将 venv 移动到没有空间的文件夹时,它又开始工作了。根据您的描述,它看起来不像,但这是我遇到的错误。

这是我的 .launch 文件在我开始工作时的样子。你的文件看起来很不一样,我想它可能也与此有关?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "classify_x",
            "type": "python",
            "request": "launch",
            "program": "classify_x.py",
            "console": "integratedTerminal",
            "args": ["orig.csv","output.csv"],
        },    
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2019-06-22
    • 2020-02-13
    • 1970-01-01
    相关资源
    最近更新 更多