简体   繁体   English

文件从 python.exe 运行

[英]File runs from python.exe

I just switch laptops and everything seems to be normal except this.我只是换了笔记本电脑,除此之外一切似乎都很正常。 When I open CMD and try to run a file like py filename.py当我打开 CMD 并尝试运行像py filename.py这样的py filename.py

it comes up with an error它出现了一个错误

C:\\Users\\john\\AppData\\Local\\Programs\\Python\\Python37\\python.exe: can't open file 'filename.py': [Errno 2] No such file or directory

It defaults to the python.exe file.它默认为 python.exe 文件。 It does it for every file that I try to run as well.它也为我尝试运行的每个文件执行此操作。 I am in the correct directory (the directory where the actual file is in) but it keeps defaulting to that error.我在正确的目录(实际文件所在的目录)中,但它一直默认为该错误。 I am running windows 10 with python 3.7.3.我正在使用 python 3.7.3 运行 Windows 10。

You may have to change the default directory where your terminal looks for the python.exe file and its packages.您可能需要更改终端查找 python.exe 文件及其包的默认目录。 You must change both.你必须改变两者。 One variable points to the python[version] folder and the other points to the python[version]\\scripts folder.一个变量指向 python[version] 文件夹,另一个变量指向 python[version]\\scripts 文件夹。

This page shows you how to redirect your terminal in windows:此页面向您展示如何在 Windows 中重定向终端:

https://superuser.com/questions/1399544/how-to-change-default-python-executable-on-windows-10/1399546 https://superuser.com/questions/1399544/how-to-change-default-python-executable-on-windows-10/1399546

Another tip is that you must change these two identical directories for both the "user variables" and the "system variables" listed in the section below it.另一个提示是,您必须为下面部分中列出的“用户变量”和“系统变量”更改这两个相同的目录。 I believe the Python installation has probs with this, especially if it's a reinstall or a failed update.我相信 Python 安装有这个问题,尤其是在重新安装或更新失败的情况下。 And on Windows in general.一般在 Windows 上。

Best,最好的事物,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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