Can't run Python programs from the terminal window, how do I fix this? (Windows 10, Python version 3.8.5)

Question:

I’ve been studying Python for a month now and normally I run all my programs in Sublime Text 3.

Today I learn to run Python programs in the terminal window as introduced in this section of the Automate the Boring Stuff with Python book following this video. Basically, I followed the instruction in the video and created the hello.py file as below:

#! python3
print('Hello, World!')

Then I opened the Command Prompt to run the file with the command: py.exe c:usersdanhmypythonscriptshello.py,
an error pops-up and states that "This app can’t run on your PC" and a line says that Access is denied. I spent the whole day trying to fix this problem but still I couldn’t get it running.

One thing is when I change the directory of the Command Prompt to run the file to C:Windowssystem32 (or run the Command Prompt as Administrator) and then run the command py.exe c:usersdanhmypythonscriptshello.py, it runs the file without any problem as in this image.

Does anyone know how to fix this problem? Any help is appreciated. Thanks!


Asked By: Danh Tran

||

Answers:

It looks like you’re trying to use Microsoft’s new Windows 10 Metro-based auto-installing version of Python. It’s included by default but, as you’ve found, it doesn’t work very well.

Try installing the version from the Python website.

If you’ve got a 32-bit copy of Windows, make sure to install the 32-bit version; Windows isn’t very good at running 64-bit programs from a 32-bit kernel. You can check by looking in your C: drive; if you haven’t got a Program Files (x86) folder, install the 32-bit version.

Answered By: wizzwizz4

I solved the problem.

When I looked into my user directory at C:Users<Username>, it appears that there is a py.exe file that has 0 bytes.

I was told in this thread that the py.exe file shouldn’t be in my user directory so I removed that file and it fixed the problem.

I still don’t know how the py.exe file got into my user directory and why it has 0 bytes so I’m not sure this solution could help others. For now, I will accept my own answer because it solves the problem in my case.

Answered By: Danh Tran

python.exe inside my envScripts became 0kb for some reason. So I created another virtual-env and copied python.exe from there to this folder. then it started working.

Answered By: RandString
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.