johnsmith
johnsmith

Reputation: 131

Python script works fine on Linux, on Windows, causes WindowsError: [Error 5] Access is denied

I have a simple python script that works fine on Linux, I moved it to a Windows machine and when I attempt to run it, I get the following exception message:

Traceback (most recent call last):
  File "C:\path\to\my\script.py", line 57, in <module>
    retcode = subprocess.call(command)
  File "C:\Python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 5] Access is denied

Here is the snippet of code that throws the exception:

print 'command is:',command
retcode = subprocess.call(command)

The console out put is as follows:

command is: ['c:\python27', 'C:\path\to\script.py', '--mode=2', '--check-temp=false', '--all-seasons=true', '--added=1', '--max-temp=2000', '--source=2', '--loc=XYZ'] Unhandled exception while debugging...

Anyone knows how to fix this?

I am running python v2.7.3 on Windows XP Professional

Upvotes: 3

Views: 3494

Answers (2)

Harry Johnston
Harry Johnston

Reputation: 36318

According to the documentation, the first item in the argument sequence (in this case, the first element of command) is interpreted as the program to execute.

Looking at the first element of command, it would appear that you're trying to execute a directory. Windows (somewhat non-intuitively) returns an access denied error whenever you try to read from a directory as if it were a file, and the same thing happens if you try to execute one.

Instead of c:\python27 you probably want c:\python27\bin\python.exe or something similar. At any rate, you need to be pointing at the executable, not at the directory. I'm not sure why this works for you on Linux.

Upvotes: 5

Jon Clements
Jon Clements

Reputation: 142156

Your program doesn't have access to the file... check permissions on the file you're trying to access, then go from there... (ie, either elevate the Python interpreter's permissions, or reduce access required to said resource) - either way - tread carefully.

Upvotes: 1

Related Questions