Python [WinError 5] Access is denied in Visual Studio 2019

985 Views Asked by At

I am trying to add some code to the git-p4.py script and the program is now failing when I attempt to run it in Visual Studio 2019 professional.

I get the same error with python3.7.4 or 3.8.0 (I uninstalled python2.7 attempting to address this but I don't recall if the error is identical.) I have python installed as all users and in a non-program files directory: c:\langs\python38 directory.

Visual studio fails on the following code:

    shell=False
    stdin_file = None
    cmd = ['p4.exe', 'login']
    p4 = subprocess.Popen(cmd,
                          shell=expand,
                          stdin=stdin_file,
                          stdout=subprocess.PIPE)

I have simplified the parameters for the question.

The result of this command is the following:

 File "C:\System\Windows\python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\System\Windows\python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  File "c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\_pydev_bundle\pydev_monkey.py", line 480, in new_CreateProcess
    return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
PermissionError: [WinError 5] Access is denied

I have set the python executable to be run as an administrator and I have also set devenv.exe for VS2019 to run as an administrator. But to no avail.

This is not supposed to be the issue I am debugging, it was working about 6 months ago. Any help or workaround would be appreciated.

1

There are 1 best solutions below

0
sophros On

It is difficult to know what exactly is wrong without more information about the setup of your Perforce installation on the machine. However, I am wondering if you have p4.exe in the %PATH% and permissioned for user running VS?

You also do not have to set up stdin to None. It is the default.