简体   繁体   中英

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 SAM Cli commands are working fine while executing from terminal. However, while trying to debug or build from vscode it throws an error. Seems like vscode is picking a different path for python 3.8 version.

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:

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. Inside the file create

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

replace the python path with the path to your python binary file.

It worked once after setting the python path /usr/local/opt/python@3.8/bin/python3 in vscode View > command palette > Python: select interpreter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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