简体   繁体   中英

Access Denied When Running .bat file, Windows 10

Windows 10 Home Version 1607. Python 3.5.2

I'm new to python, I've tried to run python script using a batch file. I've added my folder contain batch files to the PATH Environment Variables. Have tried to run my python script by typing in 'HelloWorld' on Win+R

However a error message pops saying 'This app can't run on your pc' and the cmd keeps on returning the current message

Access Denied. Press any key to continue.....

Python Script. Saved as HelloWorld.py

#! python3

import sys

print('Hello World')
print(sys.argv)

Batch File. Saved as HelloWorld.bat

@py C:\Users\Anthony\MyPythonScripts\HelloWorld.py %*
@pause

You are mistakenly using py instead of python to execute your script.

This causes the messages you are getting.

If you use python 3.5.2 or python 2.7 in a project or in a script to run it you should use the command d:\\Users\\nameofuser>python nameofmyscript .

For exemple i have a script in python2:

import os 

print "Hello wolrd! I'm a rabbit!"

i will run it with python rabbit.py

answer: Hello wolrd! I'm a rabbit! Hello wolrd! I'm a rabbit!

if i have my script in python 3

import os 

print("Hello wolrd! I'm a rabbit!")

this time i can use python3 rabbit.py or python rabbit.py

The only thing you can't do is to use python3 for a python 2.7 script you will have a SyntaxError

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM