[英]Can't run Python programs from the terminal window, how do I fix this? (Windows 10, Python version 3.8.5)
I've been studying Python for a month now and normally I run all my programs in Sublime Text 3.我已经研究 Python 一个月了,通常我在 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 .今天,我学习了如何在终端 window 中运行 Python 程序,正如本节介绍的使用 Python 自动化无聊的东西这本书的视频。 Basically, I followed the instruction in the video and created the hello.py file as below:
基本上,我按照视频中的说明创建了hello.py文件,如下所示:
#! python3
print('Hello, World!')
Then I opened the Command Prompt to run the file with the command: py.exe c:\users\danh\mypythonscripts\hello.py
, an error pops-up and states that "This app can't run on your PC" and a line says that Access is denied .然后我打开命令提示符以使用以下命令运行文件:
py.exe c:\users\danh\mypythonscripts\hello.py
,弹出一个错误并指出“此应用程序无法在您的 PC 上运行”和一行说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:Windows\system32 (or run the Command Prompt as Administrator) and then run the command py.exe c:\users\danh\mypythonscripts\hello.py
, it runs the file without any problem as in this image .一件事是当我将命令提示符的目录更改为C:Windows\system32 (或以管理员身份运行命令提示符),然后运行命令
py.exe c:\users\danh\mypythonscripts\hello.py
,它运行该文件没有任何问题,如图所示。
Does anyone know how to fix this problem?有谁知道如何解决这个问题? Any help is appreciated.
任何帮助表示赞赏。 Thanks!
谢谢!
It looks like you're trying to use Microsoft's new Windows 10 Metro-based auto-installing version of Python.看起来您正在尝试使用 Microsoft 的新 Windows 10 基于 Metro 的自动安装版本 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 .尝试从 Python 网站安装版本。
If you've got a 32-bit copy of Windows, make sure to install the 32-bit version;如果您有 Windows 的 32 位副本,请确保安装 32 位版本; Windows isn't very good at running 64-bit programs from a 32-bit kernel.
Windows 不太擅长从 32 位 kernel 运行 64 位程序。 You can check by looking in your C: drive;
您可以查看您的 C:驱动器; if you haven't got a Program Files (x86) folder, install the 32-bit version.
如果您没有Program Files (x86)文件夹,请安装 32 位版本。
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.当我在
C:\Users\<Username>
查看我的用户目录时,似乎有一个py.exe
文件有 0 个字节。
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.我在这个线程中被告知
py.exe
文件不应该在我的用户目录中,所以我删除了该文件并解决了问题。
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.我仍然不知道
py.exe
文件是如何进入我的用户目录的,以及为什么它有 0 个字节,所以我不确定这个解决方案是否可以帮助其他人。 For now, I will accept my own answer because it solves the problem in my case.现在,我会接受我自己的答案,因为它解决了我的问题。
python.exe
inside my env\Scripts\
became 0kb for some reason.由于某种原因,我的
env\Scripts\
中的python.exe
了 0kb。 So I created another virtual-env and copied python.exe
from there to this folder.所以我创建了另一个虚拟环境并将
python.exe
从那里复制到这个文件夹。 then it started working.然后它开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.