How to export PATH to "sam build" command?
Asked Answered
C

4

13

I'm developing AWS Lambda function on PyCharm. When I do "Run" button, Following error message.

/usr/local/bin/sam build MyFunction --template /Users/miyashiiii/Works/myapp/myapp/template.yaml --build-dir /Users/miyashiiii/Works/myapp/myapp/.aws-sam/build
Building codeuri: myapp/ runtime: python3.7 metadata: {} functions: ['MyFunction']

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

python3.7 is on my PATH, and other some locations is on my PATH, but locations list includes only '/usr/bin/python'.

And when I do same command (/usr/local/bin/sam build ~~) on terminal, It succeed.

How to export PATH to "sam build" command?

Compiler answered 7/12, 2020 at 11:20 Comment(0)
B
28

I solved the problem for python3.8 (same for python3.7 I suppose) by linking executable into /usr/local/bin

ln -sf /usr/local/opt/[email protected]/bin/python3.8 /usr/local/bin/

[EDIT Nov2021] it's /opt/homebrew/opt/[email protected]/bin/python3 nowadays [/EDIT]

To find your python directory if installed by homebrew: brew info [email protected]

Also, you'd probably prefer running SAM inside a docker container (option sam build --use-container with CLI)

In pycharm: Activate the build function inside a container

Bethsaida answered 11/12, 2020 at 17:9 Comment(1)
This solved the problem for me. Note: I had to use "/usr/bin/python" as the location for WSL.Karafuto
D
5

SAM expects your version of Python do be on PATH, as seen here

To find your python directory if installed by homebrew: brew info [email protected]

In my case, this yielded /usr/local/opt/[email protected]/libexec/bin

Then add that to PATH with:

export PATH=$PATH:<Your Python version's path here>
export PATH=$PATH:/usr/local/opt/[email protected]/libexec/bin

You can confirm that it has been appended by running echo $PATH, and you should see your new path at the end of the output.

sam build should then find your Python version

Despumate answered 23/6, 2021 at 2:13 Comment(0)
E
0

Added a 3.9 environment variable and tried linking folders but didn't work for me.

The solve for me was downloading Python3.9 and then creating/selecting a new Python Interpreter in VSCode. This article helped me

I'm using Windows, WSL, VSCode, & Python3.10 - but needed 3.9 for SAM CLI and got the the error below

Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : ['C:\\Python310'] which did not satisfy constraints for runtime: python3.9. Do you have python for runtime: python3.9 on your PATH?
Explant answered 18/5, 2022 at 19:8 Comment(0)
F
0

If you are using Mac, zshell and Python3.8 installed via homebrew, run the following command:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

And then source your .zshrc, so changes take effect:

source ~/.zshrc

Freida answered 8/6, 2022 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.