简体   繁体   English

Python Visual Studio 代码的路径问题

[英]Python path issue with Visual studio code

I am experiencing an issue with AWS Lamda (python 3.8) while trying to debug it locally.我在尝试本地调试 AWS Lamda (python 3.8) 时遇到问题。 AWS SAM Cli commands are working fine while executing from terminal.从终端执行时,AWS SAM Cli 命令运行良好。 However, while trying to debug or build from vscode it throws an error.但是,在尝试从 vscode 调试或构建时,它会引发错误。 Seems like vscode is picking a different path for python 3.8 version.似乎 vscode 正在为 python 3.8 版本选择不同的路径。

Here is the configuration path snapshot from terminal:这是来自终端的配置路径快照:

mbp$ which python
/usr/bin/python
mbp$ which python3
/usr/local/opt/python@3.8/bin/python3
mbp$ which aws
/usr/local/bin/aws
mbp$ which sam
/usr/local/bin/sam
mbp$ python --version
Python 2.7.16
mbp$ python3 --version
Python 3.8.8

Here is the visual-studio-code log:这是 visual-studio-code 日志:

2021-02-22 20:53:24 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 20:53:24 [INFO]: Building SAM application...
2021-02-22 20:53:24 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctklNIOzG/output --template /Users/mb/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctklNIOzG/debug-requirements.txt]
2021-02-22 20:53:24 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 20:53:24 [INFO]: Starting SAM application locally
2021-02-22 20:53:24 [INFO]: AWS.running.command
2021-02-22 20:53:24 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 20:53:24 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 20:53:24 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 20:53:24 [INFO]: Waiting for SAM application to start...
2021-02-22 20:53:24 [INFO]: Attaching debugger to SAM application...
2021-02-22 20:53:41 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 20:53:41 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
2021-02-22 21:56:05 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 21:56:05 [INFO]: Building SAM application...
2021-02-22 21:56:05 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkIy5kkF/output --template /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctkIy5kkF/debug-requirements.txt]
2021-02-22 21:56:05 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 21:56:05 [INFO]: Starting SAM application locally
2021-02-22 21:56:05 [INFO]: AWS.running.command
2021-02-22 21:56:05 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 21:56:05 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 21:56:05 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 21:56:05 [INFO]: Waiting for SAM application to start...
2021-02-22 21:56:05 [INFO]: Attaching debugger to SAM application...
2021-02-22 21:57:04 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 21:57:04 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.

Another solution that you can try is create a .vscode folder in your project directory and then create a settings.json file inside that directory.您可以尝试的另一个解决方案是在您的项目目录中创建一个.vscode文件夹,然后在该目录中创建一个settings.json文件。 Inside the file create在文件里面创建

{
    "python.pythonPath": "<python path>",
}

replace the python path with the path to your python binary file.将 python 路径替换为 python 二进制文件的路径。

It worked once after setting the python path /usr/local/opt/python@3.8/bin/python3 in vscode View > command palette > Python: select interpreter在 vscode 视图 > 命令面板 > Python: select 解释器中设置 python 路径 /usr/local/opt/python@3.8/bin/python3 后它工作了一次

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

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