Sublime Forum

[Errno 2] No such file or directory: 'python'

#1

I’ve searched on this forum and I can see this issue has come up before but I’m not seeing anything that is a clear solution.

I’m running Sublime Text 4152 on Mac OS 13.3.1 (22E261).
I can see my existing (and working in Jupyter) Anaconda 3 install listed in Settings > Package Settings > Conda and it is correctly showing “executable”: “~/anaconda3/bin/python3”
I have Conda selected as my ‘Build System’
When I run any .py file I get the following:

[Errno 2] No such file or directory: ‘python’
[cmd: [‘python’, ‘-u’, ‘/Users/axis_mundi/Documents/test_01.py’]]
[dir: /Users/axis_mundi/Documents]
[path: /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/axis_mundi/Library/Application Support/JetBrains/Toolbox/scripts]
[Finished]

Doesn’t seem to make any difference where the .py file is located.
I can see that [path: /usr/… is not looking like it’s making much sense - but I can’t see any way of changing that.

0 Likes

#2

This part of the error diagnostic tells you what the build system is trying to execute:

[cmd: [‘python’, ‘-u’, ‘/Users/axis_mundi/Documents/test_01.py’]]

So, it’s trying to execute a program named python, and giving it the full name of the current file.

You mention that your Conda settings specify:

“executable”: “~/anaconda3/bin/python3”

However, that is python3 and not python; hence when the build tries to execute, it presumably is failing because there is no program named python anywhere. Generally speaking, python is Python 2 and python3 is Python 3 (except on windows where they’re all python and the world makes no sense).

I would guess that the build you have selected is not doing what you think it is doing, in as much as it’s set to run the wrong Python.

The build system that ships with Sublime for Python out of the box (in the build that you’re using) is:

{
	"cmd": ["python3", "-u", "$file"],
	"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
	"selector": "source.python",

	"env": {"PYTHONIOENCODING": "utf-8"},

	"windows": {
		"cmd": ["py", "-u", "$file"],
	},

	"variants":
	[
		{
			"name": "Syntax Check",
			"cmd": ["python3", "-m", "py_compile", "$file"],

			"windows": {
				"cmd": ["py", "-m", "py_compile", "$file"],
			}
		}
	]
}

So, since you have a python3 installed, if you used this build it would likely work better than the one that you have currently, if your PATH was correct.

As outlined in the diagnostics, the PATH contains the following paths:

/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
/Users/axis_mundi/Library/Application Support/JetBrains/Toolbox/scripts

None of those is /Users/axis_mundi/anaconda/bin, so even if you did use the default build, it won’t be able to find that particular python3 when it looks; updating the PATH might resolve that.

The PATH is not a Sublime concept, it’s an OS concept; you need to adjust the profile files for your shell (likely zsh if you’re on a recent MacOS, bash if not) to augment the PATH, and then restart Sublime for the change to take effect.

Alternately, if you’re using something that is Anaconda related in Sublime, which it seems like you are since you have settings for it, its config might need to be tweaked, or you might have to select a different build so that it knows to look in the correct place.

1 Like