簡體   English   中英

Python Visual Studio 代碼的路徑問題

[英]Python path issue with Visual studio code

我在嘗試本地調試 AWS Lamda (python 3.8) 時遇到問題。 從終端執行時,AWS SAM Cli 命令運行良好。 但是,在嘗試從 vscode 調試或構建時,它會引發錯誤。 似乎 vscode 正在為 python 3.8 版本選擇不同的路徑。

這是來自終端的配置路徑快照:

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

這是 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.

您可以嘗試的另一個解決方案是在您的項目目錄中創建一個.vscode文件夾,然后在該目錄中創建一個settings.json文件。 在文件里面創建

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

將 python 路徑替換為 python 二進制文件的路徑。

在 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