Skip to content Skip to sidebar Skip to footer

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

Solution 1:

The Terminal loads a number of files that can modify your PATH variable, including ~/.profile, ~/.bashrc, ~/.bash_profile, etc. These do not get loaded when the Mac OS X system UI is started / when you login to your user profile via the Finder app. Consequently, apps started via Finder do not inherit the PATH and other environment variables set in these files.

Different versions of Mac OS X have different solutions for setting environment variables such that they are loaded by Finder. Older versions of Mac OS X supported a file called ~/.MacOSX/environment.plist that could be used to specify the environment. Newer versions of OS X use the launchctl tool to set environment variables that are seen by apps started with launchctl (which is responsible for starting the system UI and other system services).

In short, use the command:

launchctl setenv <variable-name><variable-value>

To set this environment variable for the current user. Apps run as the current user will inherit the variables that are specified. So, for example, you could do:

launchctl setenv PATH "$PATH"

... from the Terminal to apply your current PATH value to the system for your account.

See also:

Solution 2:

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

Post a Comment for "Mac Os X /bin/bash: Python: Command Not Found In Some Ide"