由于 python 路径问题,我无法在 vscode (mac) 中调试我的脚本

问题描述

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

在终端中,在 python3 中,使用 import sys print(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",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"
}

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

非常感谢,

山姆

解决方法

您的项目文件夹是否位于包含空格“”的路径中?当我使用的 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","program": "${file}","console": "integratedTerminal"
        }
    ]
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...