aws-toolkit-jetbrains: `sam build` cannot find python 3.8 even though it's on the PATH

Describe the bug The sam build command is failing when run by PyCharms, indicating python3.8 cannot be found on my PATH:

/usr/local/bin/sam build HelloWorldFunction --template /Users/ryonlife/peg/peg-sam-hello-world/template.yaml --build-dir /Users/ryonlife/peg/peg-sam-hello-world/.aws-sam/build
Building resource 'HelloWorldFunction'

Build Failed
Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : ['/Users/ryonlife/.pyenv/shims/python3.8', '/Users/ryonlife/.pyenv/shims/python', '/usr/bin/python'] which did not satisfy constraints for runtime: python3.8. Do you have python for runtime: python3.8 on your PATH?

However, the first two locations are indeed python 3.8:

MacBook-Air:~ ryonlife$ /Users/ryonlife/.pyenv/shims/python3.8
Python 3.8.0 (default, May 11 2020, 00:49:45) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
MacBook-Air:~ ryonlife$ /Users/ryonlife/.pyenv/shims/python
Python 3.8.0 (default, May 11 2020, 00:49:45) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

To reproduce

  1. In the PyCharms code editor, click the run icon next to the lambda handler function.
  2. View error message in the build output console.
  3. Run the command with success in Terminal outside of PyCharms:
MacBook-Air:peg-sam-hello-world ryonlife$ which python
/Users/ryonlife/.pyenv/shims/python
MacBook-Air:peg-sam-hello-world ryonlife$ python --version
Python 3.8.0
MacBook-Air:peg-sam-hello-world ryonlife$ sam build
Building resource 'HelloWorldFunction'
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided

Your Environment

  • OS: macOS 10.15.4
  • JetBrains product: PyCharm CE
  • JetBrains product version: 2020.1
  • AWS Toolkit version: aws-cli/2.0.10 Python/3.8.2 Darwin/19.4.0 botocore/2.0.0dev14
  • SAM CLI version: 0.48.0
  • JVM/Python version: 3.8.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I had this as well. Don’t want to change /usr/bin/python of course and 3.9 is my standard python from brew. Adding this to ~/.profile fixed it. So basically, python 3.9 will always be found by default but when SAM goes looking for 3.8 it will find it.

# Add Python3.8 so aws sam can find it
export PATH=$PATH:/usr/local/opt/python@3.8/bin

By the way, I got the same error when I was trying to run a sample application. After looking a little bit, I noticed that in the template.yml the runtime was set to python3.7 and I was using python3.8. As soon as I updated the template.yml to match my python runtime the error went away. Hope this helps someone.

Yes Daniel,

It did help, appreciate it.

Thank you,

You can modify template.yaml, and change Runtime: python3.7 to Runtime: python3.8