简体   繁体   English

从 cmd 运行时,.py 文件在文本编辑器中打开

[英].py files opens up in a text editor when run from cmd

Whenever I try to run a .py file from cmd it opens up in a text editor(np++).每当我尝试从 cmd 运行 .py 文件时,它都会在文本编辑器(np++)中打开。 I'm trying to run the following:我正在尝试运行以下命令:

django-admin.py startproject testprj

Even if I run 'setup.py install'即使我运行“setup.py install”

You need to change the file association so that .py files open with Python executable, typically located in C:\\Python<version>\\ and not Notepad++您需要更改文件关联,以便使用 Python 可执行文件打开 .py 文件,通常位于C:\\Python<version>\\而不是 Notepad++

Changing this should be easy, but here is how to do it.改变它应该很容易,但这里是如何做到的。

Also, read here on to set the environment path so that the Python executable is found without you having to navigate to C:\\Python2.6.此外,请继续阅读此处设置环境路径,以便无需导航到 C:\\Python2.6 即可找到 Python 可执行文件。

Your Windows file associations are set to open .py files in a text editor.您的 Windows 文件关联设置为在文本编辑器中打开.py文件。 You have to change those to use the python.exe interpreter, or you can prefix all your commands with python, like this:您必须更改这些以使用python.exe解释器,或者您可以使用 python 为所有命令添加前缀,如下所示:

python django-admin.py startproject testprj

If you want to change your file associations, and you are running Vista or Windows 7, you can change them in 'Control Panel'->'Default Programs'->'Associate a file type or protocol with a program'如果要更改文件关联,并且运行的是 Vista 或 Windows 7,则可以在“控制面板”->“默认程序”->“将文件类型或协议与程序关联”中更改它们

It is very easy: `python (or directory to python.exe with python.exe on the end) filename (Or a again directory to the file with the name and extension on the end.) any arguments. 这很容易:`python(或python.exe的目录,最后是python.exe)文件名(或者是文件的另一个目录,最后是名称和扩展名。)任何参数。

So if i would want to run setup.py on my desktop: I could eather: 所以,如果我想在我的桌面上运行setup.py:我可以:

use cd to get all the way to the folder where the .py file is 使用cd来获取.py文件所在的文件夹

and then 然后

"pathtopythonwithoutnameonend\python.exe" (In "!) setup.py 

or 要么

python  "pathtofolderinwhichsetup.pyiswithoutname\setup.py" (In "!)

It is that easy. 就这么简单。 Seriously. 认真。

暂无
暂无

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

相关问题 运行django开发服务器的服务器在文本编辑器中打开manage.py - running django development server opens manage.py in text editor 来自 cmd 的 Running.py 文件打开 python 修改设置 - Running .py file from cmd opens the python modify setup python.exe 在我运行 python **.py 时崩溃,来自 windows ZDFFF0A7FA1A55C8C1A4966C19FDA445 - python.exe was crashed when I run python **.py from windows cmd 当我将“.py”扩展名与 CMD 命令一起使用时,VSCode 会启动 - VSCode starts up when I use “.py” extension with CMD commands 为什么在 Vim 文本编辑器的 .py 文件中 word 文件会高亮显示? - Why is the word file get highlighted in .py files in the Vim text editor? 如何直接从cmd运行.py脚本? - How do I run a .py script directly from cmd? 在使用py2exe构建的可执行文件中执行subprocess.popen()时,如何避免cmd弹出和关闭? - How to avoid cmd from popping up and closing when subprocess.popen() is executed in an executable built with py2exe? Pyside UI弹出然后在从cmd运行之前消失,然后才能使用它? - Pyside UI pops up and then disappears when run from cmd before it can be used? 尽管安装了 tensorflow,当我尝试从 CMD 运行文件时,出现“ModuleNotFoundError: No module named 'tensorflow'”错误 - Inspite of installing tensorflow, `ModuleNotFoundError: No module named 'tensorflow'` error occurs when I try to run files from CMD 在Windows 8中编写了一个python脚本,并使用py2exe获得了一个exe,当移至Windows 7时,它将打开cmd,然后关闭 - Wrote a python script in windows 8 and used py2exe to get a single exe, when moved to windows 7 it opens cmd then closes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM