简体   繁体   English

无法从终端 window 运行 Python 程序,我该如何解决? (Windows 10、Python 版本 3.8.5)

[英]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.

相关问题 Python 3.8.5 安装在 MacOS 上,但 python --version 返回 2.7.16 -- 我该如何解决这个问题? - Python 3.8.5 installed on MacOS but python --version returns 2.7.16 -- How do I fix this? 如何修复以下错误以运行简单的 Python 程序? VSCode 终端错误 - How Do I Fix The Error Below to Run Simple Python Programs? Error In VSCode Terminal 当安装程序不起作用时,如何正确卸载/修复 python 3.8.5? - How do I properly uninstall/fix python 3.8.5 when the installer doesn't work? PYTHON:您如何从终端运行程序? - PYTHON: How do you run your programs from the terminal? 我如何在 Windows 10 上为 python 3.8.5 安装 pyaudio - how do i install pyaudio on windows ten for python 3.8.5 从python运行终端程序 - Run terminal programs from python 如何修复终端中显示的 python 版本? - How do I fix my python version showing up in terminal? 如何修复 python 3.8.5。 错误“导入错误:无法从‘io’(未知位置)导入名称‘open_code’” - How do I fix python 3.8.5. error "ImportError: cannot import name 'open_code' from 'io' (unknown location)" 使用 Python 3.8.5 在 Windows 10 上安装 plotly 时出现问题 - Problems with installing plotly on Windows 10 with Python 3.8.5 如何在Windows 7中运行python程序? - How to run python programs in Windows 7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM