pythonbashmacossublimetext3coderunner

Mac OS X /bin/bash: python: command not found in some IDE


When I compiled test.py(a very simple Python file) in Sublime Text or CodeRunner, I got the error:/bin/bash: python: command not found. Then I input python test.py in the Terminal app, it worked. Later I downloaded Pycharm and compiled the file again, it worked too!

So I assume there is some kind of path setting or something else that was not set correctly. I've searched for quite a long time on the internet but no use. Please help or try to give some ideas how to solve the problem.

Here are some details:

  1. I've tried inserting #! /usr/bin/python at the top of test.py file but no use

  2. The output of echo "$PATH" in Terminal is /usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/chenyang/Downloads/android-sdk-macosx/platform-tools

  3. I've found several versions of Python in my macbook :2.6, 2.7, 3.2, 3.3, 3.5. Under the folder /System/Library/Frameworks/Python.framework/Versions I found 2.6, 2.7. Under the folder /Library/Frameworks/Python.framework/Versions I found 3.2, 3,3, 3.5.


I've solved the problem myself and post the answer below


Solution

  • Thank everyone who helps. I've solved the problem myself.

    I've always been using zsh instead of bash. After updating CodeRunner to the newest version, the app uses bash by default. So I just need go to Preference>Advanced menu and untick the checkbox invoke bash in login mode when running code to solve the problem.

    In Sublime Text3, the solution is in this link:https://stackoverflow.com/a/38574286/6631854