Sublime Forum

[WinError 5] Access is denied

#1

Hi, I’m trying to import python 3 into my sublime text but it keeps saying “access is denied”. this is the code im using, please help.

{
“cmd”: [“C:\Users\(MY NAME)\AppData\Local\Programs\Python\Python36”, “-u”, “$file”],
“file_regex”: “^[ ]File "(…?)”, line ([0-9]*)",
“selector”: “source.python”
}

and pressing ctrl B in another system with the code… my friend helped me set this up ando i dont know much so i couldn’t help.

import sys
print(sys.version)

this is the error.
[WinError 5] Access is denied
[cmd: [‘C:\Users\MYNAME\AppData\Local\Programs\Python\Python36’, ‘-u’, ‘’]]
[dir: C:\Program Files\Sublime Text 3]
[path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\MATLAB\R2016b\runtime\win64;C:\Program Files\MATLAB\R2016b\bin;C:\Program Files\MATLAB\R2016b\polyspace\bin;C:\Program Files\MATLAB\MATLAB Runtime\v93\runtime\win64;C:\WINDOWS\System32\OpenSSH;C:\Program Files\MiKTeX 2.9\miktex\bin\x64;C:\Users\MYNAME\AppData\Local\Microsoft\WindowsApps;]
[Finished]

0 Likes

#2

The script is run from within a readonly path unless you run ST with elevated admin privileges. If it tries to write something to that path, the error is quite common.

0 Likes

#3

What is the solution to this problem? I cannot use sublime atm…

Many have this issue I saw…

0 Likes

#4

TL;DR: The build file is broken and needs to be fixed, because you can’t run a directory, you can only run programs.

The OP’s original problem is two-fold, First, they specified the command to be executed as the folder that the python interpreter is installed in instead of a path to the executable itself, and secondly they used cmd instead of shell_cmd. Technically that is not a problem except that it obfuscates what’s going on.

To demonstrate, open the Sublime console with Ctrl+` or View > Show Console from the menu, and then enter this command and press enter.

window.run_command("exec", {"shell_cmd": "c:\\"})

That tells the window to run the exec command (which is what executes builds) and tells it to pass a command line of c:\ to the windows command intepreter. The result is a build window popping up, which includes this error:

'c:\' is not recognized as an internal or external command,
operable program or batch file.

Windows is telling us that it can’t find a program named c:\, which makes sense because that is not a program, that’s the name of a folder on your hard drive.

Now do the same thing but enter this instead:

window.run_command("exec", {"cmd": ["c:\\"]})

This is an alternate way to do the same thing as above, except that where shell_cmd gives a command line to the windows command interpreter to run it, cmd directly tells windows “run this program”.

As we already know, this isn’t a program, it’s the name of a folder. However we told windows it was a program and it should try to run it. The resulting build window says this:

[WinError 5] Access is denied

The reason access is denied is because you’re not allowed to run directories, you’re only allowed to run programs.

So, the overall moral of the story is, the OP incorrectly specified in the cmd that the program to run was the folder where Python is installed, when it should have also included the name of the Python interpreter itself. Thus, windows balks and the build fails.

In order to fix the problem, the sublime-build file needs to be modified to be correct. The easier thing to do is check the box in the Python installer that tells it to add the Python installer to the PATH. The second easiest thing to do is manually add the appropriate folder to your PATH (use Google to determine how to do that based on your OS). The third easiest thing to do is add a path key to the sublime-build file to temporarily augment the path.

3 Likes