python3 won't run from mac shell script python3 won't run from mac shell script shell shell

python3 won't run from mac shell script


Since you have the shebang line, you can do ./my_script.py and it should run with Python 3.


You can install Python 3 via Homebrew with brew install python3 and use #!/usr/local/bin/python3 as your shebang.

Not a perfect solution but still better than using the full path of the interpreter.


You could create ~./bash_profile file and export the path to python 3 bin folder, it would look like

export PATH=“path-to-python3-bin-folder:$PATH

Every time that you enter Terminal, type source ~./bash_profile and now you can call python3 as a function in terminal to call your code.

On the other hand, I would recommend you to download Anaconda, as you can create virtual environments easily with the version of python that you’d like.