0

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
A. Tran
  • 333
  • 1
  • 5
  • 13

2 Answers2

1

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

This causes the messages you are getting.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
0

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!

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