QWERASDFYXCV
QWERASDFYXCV

Reputation: 305

PermissionError: [WinError 5] Access denied

I am trying to call a python program with subprocess, but I get a permission error. I tried running PyCharm as an admin, but it doesn't help.

My code:

answer = subprocess.check_output("../folder python program %s %s" %(valueA, valueB), encoding = 'utf8')

The error:

Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/a/b/b_resolution.py", line 35, in <module>
    answer = subprocess.check_output("../folder python program %s %s" %(valueA, valueB), encoding = 'utf8')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\subprocess.py", line 376, in check_output
    **kwargs).stdout
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\subprocess.py", line 453, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access Denied

Does someone know how I can fix this permission error?

Upvotes: 8

Views: 52238

Answers (6)

Haileyesus
Haileyesus

Reputation: 11

If you have opened the requested file in the file explorer close and mostly I mresolve this issue when I reopened VScode as an admin.

Upvotes: 1

Samith Orozco
Samith Orozco

Reputation: 1

In my case, the error was because the path was not complete.

I changed this:

cmd = r'C:/Program Files (x86)/path'

to this:

cmd = r'C:/Program Files (x86)/path/completepath'

(also check you use the right slash \ or / for windows)

Upvotes: 0

Uros Randelovic
Uros Randelovic

Reputation: 515

close file explorer...

dumb but if you have the folder open in the explorer and you're trying to do anything to the folders/files you'll get this error

Upvotes: 7

djvg
djvg

Reputation: 14255

Although it doesn't answer the original question, this PermissionError also arises if you (accidentally) try to run a directory, instead of a file.

For example, any of these will raise the PermissionError: [WinError 5] Access is denied:

subprocess.check_output('.')
subprocess.run('.')

where '.' represents the path to the current directory, as a minimal example.

On the other hand, if you try to run a non-existent file, you'll get a more useful FileNotFoundError: [WinError 2] The system cannot find the file specified.

Tested with python 3.10.6 on Windows and Ubuntu. On Ubuntu the examples above raise a PermissionError: [Errno 13] Permission denied.

Upvotes: 9

QWERASDFYXCV
QWERASDFYXCV

Reputation: 305

I fixed the problem by myself the python command comes before the path. Like this:

answer = subprocess.check_output("python ../folder program %s %s" %(valueA, valueB), encoding = 'utf8')

But I had the problem that it says:

can't find '__main__' module in '../pydig'

Solved that aswell with writing the program name included in the path:

answer = subprocess.check_output("python ../folder/program %s %s" %(valueA, valueB), encoding = 'utf8')

Upvotes: 2

user11187717
user11187717

Reputation:

Check the file permissions for your current user.

Right click on the file and in security you can see file permissions for users.

If you haven't permission to read file, Advanced > Select a principal then check this doc.

Upvotes: 2

Related Questions