简体   繁体   English

如何运行python程序而不是在记事本中打开?

[英]How do I get a python program to run instead of opening in Notepad?

I am having some trouble with opening a .py file. 我在打开.py文件时遇到了一些麻烦。 I have a program that calls this .py file (ie pathname/example.py file.txt), but instead of running the python program, it opens it in Notepad. 我有一个程序调用此.py文件(即pathname / example.py file.txt),但它不是运行python程序,而是在记事本中打开它。 How to I get it to run? 如何让它运行?

The program itself takes in a file, and creates an output that is more readable. 程序本身接收一个文件,并创建一个更具可读性的输出。

Edit: The operating system is Windows 7. And the file that is calling the python is a .bat file. 编辑:操作系统是Windows 7.并且调用python的文件是.bat文件。

Edit 2: It looks like I had to reinstall python for some reason... but it looks like it is finally working. 编辑2:看起来我不得不因某种原因重新安装python ......但看起来它终于正常工作了。 Why reinstalling never comes to mind in the first place... And then I had to change how the file extention was opened. 为什么重新安装永远不会想到...然后我不得不改变文件扩展的打开方式。 Thanks guys 多谢你们

This happened because most probably you have set notepad as the default program to open a .py file. 发生这种情况是因为很可能您已将记事本设置为打开.py文件的默认程序。 Go to default programs app in windows. 转到Windows中的默认程序应用程序。 Select choose app by extension. 选择按扩展程序选择应用。 Here search for .py files. 在这里搜索.py文件。 Change the option from notepad to python. 将选项从记事本更改为python。 This should solve your problem. 这应该可以解决您的问题。

okay. 好的。
1) i tried turning it off and on again. 1)我尝试将其关闭再打开。 2) i uninstalled and reinstalled python 2)我卸载并重新安装了python

still no joy. 仍然没有快乐。 and then! 然后!

in windows explorer there's an open with option that sets the default program that windows is pointed toward if you click on the filename or enter it on the command line. 在Windows资源管理器中有一个打开选项,用于设置窗口指向的默认程序,如果您单击文件名或在命令行输入它。 change that from notepad or whatever it is if it's not python. 如果它不是python,那么从记事本或其他任何东西改变它。 change it to python. 把它改成python。 then presto. 然后presto。 no problem-o. 没问题 - o。

Are you trying to run the program like this? 你试图像这样运行程序吗?

   /dirdir/MyPythonScript.py

try the following instead 请尝试以下方法

   python /dirdir/MyPythonScript.py

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

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