Python – Access Denied when running any Python script on Windows

pythonwindows-server-2012

I've just done a fresh install of Python 2.7.14 on Windows Server 2012. Whenever I try to execute any script, I get an Access Denied error. This is regardless of the script I try to run, even something simple like python -c "print 1" fails with the following error message in Powershell:

Program 'python.exe' failed to run: Access is deniedAt line:1 char:1
+ python -c "print 1"
+ ~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ python -c "print 1"
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

Whereas the same command in CMD just yields Access Denied.

This happens even when running as administrator with elevated UAC status, so I'm at a loss here. Any ideas as to what's going on?

Edit: Forgot to mention, for some reason interactive mode works just fine.

Best Answer

For what its worth...

I'd wager the case might very well be server antivirus. I've seen a very very similar situation with Comodo AV for Sever that was blocking script execution with its containment settings. (It was funny as it didn't do this for php, just python). We solved this by creating a new containment rule and telling it to ignore all (a file group) *.py files in a particular directory.

This worked immediately. Hope this helps!

Related Topic