在Windows中运行/调试python程序最干净的方法

时间:2022-08-06 20:21:51

Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.

默认情况下,Python for Windows附带IDLE,这是我遇到的最基本的IDE。对于编辑文件,我会坚持使用emacs,非常感谢。

However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.

但是,我想在一些其他shell中运行程序,而不是蹩脚的Windows命令提示符,它不能扩展到超过80个字符。

IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.

如果我打开文件,IDLE让我在其中运行程序,然后点击F5(去Run-> Run Module)。我宁愿只是“运行”命令,而不是通过关闭emacs文件,加载IDLE文件等的严格程序。谷歌和IDLE文档的扫描似乎没有给使用IDLE的帮助很多shell但不是它的IDE。

Any advice from the stack overflow guys? Ideally I'd either like

来自堆栈溢出的人的任何建议?理想情况下,我要么喜欢

  • advice on running programs using IDLE's shell

    关于使用IDLE shell运行程序的建议

  • advice on other ways to run python programs in windows outside of IDLE or "cmd".

    关于在IDLE或“cmd”之外的窗口中运行python程序的其他方法的建议。

Thanks,

/YGA

9 个解决方案

#1


For an interactive interpreter, nothing beats IPython. It's superb. It's also free and open source. On Windows, you'll want to install the readline library. Instructions for that are on the IPython installation documentation.

对于交互式解释器,没有什么比IPython更好。它很棒。它也是免费和开源的。在Windows上,您将要安装readline库。有关这方面的说明,请参阅IPython安装文档。

Winpdb is my Python debugger of choice. It's free, open source, and cross platform (using wxWidgets for the GUI). I wrote a tutorial on how to use Winpdb to help get people started on using graphical debuggers.

Winpdb是我选择的Python调试器。它是免费的,开源的和跨平台的(使用GUI的wxWidgets)。我写了一篇关于如何使用Winpdb来帮助人们开始使用图形化调试器的教程。

#2


You can easily widen the Windows console by doing the following:

您可以通过执行以下操作轻松扩展Windows控制台:

  • click the icon for the console window in the upper right
  • 单击右上角控制台窗口的图标

  • select Properties from the menu
  • 从菜单中选择“属性”

  • click the Layout tab
  • 单击“布局”选项卡

  • change the Window Size > Width to 140
  • 将窗口大小>宽度更改为140

This can also be saved universally by changing the Defaults on the menu.

通过更改菜单上的默认值,也可以普遍保存。

#3


I use eclipse with pydev. Eclipse can be sluggish, but I've become attached to integrated svn/cvs, block indent/unindent and run as unittest features. (Also has F5 run)

我使用eclipse与pydev。 Eclipse可能很迟钝,但我已经加入了集成的svn / cvs,阻塞缩进/取消并作为unittest功能运行。 (还有F5运行)

If your comfortable in emacs though I don't see any reason to make such a major change.

如果你对emacs感到满意,虽然我没有看到任何理由做出如此重大的改变。

I suggest instead that you replace your 'crappy command prompt' with powershell. It's not as crappy.

我建议您用powershell替换'糟糕的命令提示符'。它并不蹩脚。

(As mentioned by Soviut and The Dark - you can increase the buffer width/window size to more than 80 by title-bar>right-click>Properties>Buffer Width/Window Size edit even in crappy cmd)

(正如Soviut和The Dark所提到的 - 您可以通过标题栏>右键单击>属性>缓冲区宽度/窗口大小编辑,将缓冲区宽度/窗口大小增加到80以上,即使在蹩脚的cmd中也是如此)

#4


However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.

但是,我想在一些其他shell中运行程序,而不是蹩脚的Windows命令提示符,它不能扩展到超过80个字符。

Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height of the window and the width and height of the screen buffer. I recommend setting the screen buffer height to 9999 so you can scroll back through a long output.

单击命令提示符中的系统框(左上角),然后单击属性。在布局选项卡中,您可以设置窗口的宽度和高度以及屏幕缓冲区的宽度和高度。我建议将屏幕缓冲区高度设置为9999,这样您就可以向后滚动一个长输出。

#5


Wing IDE is awesome. They also have a free version.

Wing IDE很棒。他们也有免费版本。

#6


2017 Answer:

Try Visual Studio Code, it has great support for Python debugging, auto completion and more!

试试Visual Studio Code,它非常支持Python调试,自动完成等等!

See this link for details: https://code.visualstudio.com/docs/languages/python#_debugging

有关详细信息,请参阅此链接:https://code.visualstudio.com/docs/languages/python#_debugging

#7


I edit my Python programs in EditPlus. I've configured a user tool that allows me to run my program and have its output appear in a frame below my editor window. My configuration will even let you double click on an exception lines in the output to jump directly to the file and line where the error occurred. You can grab the user tool configuration I use from here on the EditPlus wiki.

我在EditPlus中编辑我的Python程序。我已经配置了一个用户工具,允许我运行我的程序,并使其输出显示在编辑器窗口下方的框架中。我的配置甚至可以让您双击输出中的异常行,直接跳转到发生错误的文件和行。您可以从EditPlus wiki上获取我在此处使用的用户工具配置。

Perhaps there is similar functionality you can configure that allows you to run your program and display its output in your Emacs editor!?

也许您可以配置类似的功能,允许您运行程序并在Emacs编辑器中显示其输出!?

#8


If you ever graduate to vim, you can just run the following command to start the program you're currently editing in an interactive shell:

如果你毕业于vim,你可以运行以下命令来启动你当前在交互式shell中编辑的程序:

:!python -i my_script.py

#9


I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.

我用Cygwin和Poderosa替换了cmd。可能有点矫枉过正,如果你对cmd唯一的问题就是调整大小很痛苦。

Although you use Emacs instead of Vim, so I guess you're into overkill... ;-)

虽然你使用的是Emacs而不是Vim,所以我猜你有点矫枉过正了...... ;-)

#1


For an interactive interpreter, nothing beats IPython. It's superb. It's also free and open source. On Windows, you'll want to install the readline library. Instructions for that are on the IPython installation documentation.

对于交互式解释器,没有什么比IPython更好。它很棒。它也是免费和开源的。在Windows上,您将要安装readline库。有关这方面的说明,请参阅IPython安装文档。

Winpdb is my Python debugger of choice. It's free, open source, and cross platform (using wxWidgets for the GUI). I wrote a tutorial on how to use Winpdb to help get people started on using graphical debuggers.

Winpdb是我选择的Python调试器。它是免费的,开源的和跨平台的(使用GUI的wxWidgets)。我写了一篇关于如何使用Winpdb来帮助人们开始使用图形化调试器的教程。

#2


You can easily widen the Windows console by doing the following:

您可以通过执行以下操作轻松扩展Windows控制台:

  • click the icon for the console window in the upper right
  • 单击右上角控制台窗口的图标

  • select Properties from the menu
  • 从菜单中选择“属性”

  • click the Layout tab
  • 单击“布局”选项卡

  • change the Window Size > Width to 140
  • 将窗口大小>宽度更改为140

This can also be saved universally by changing the Defaults on the menu.

通过更改菜单上的默认值,也可以普遍保存。

#3


I use eclipse with pydev. Eclipse can be sluggish, but I've become attached to integrated svn/cvs, block indent/unindent and run as unittest features. (Also has F5 run)

我使用eclipse与pydev。 Eclipse可能很迟钝,但我已经加入了集成的svn / cvs,阻塞缩进/取消并作为unittest功能运行。 (还有F5运行)

If your comfortable in emacs though I don't see any reason to make such a major change.

如果你对emacs感到满意,虽然我没有看到任何理由做出如此重大的改变。

I suggest instead that you replace your 'crappy command prompt' with powershell. It's not as crappy.

我建议您用powershell替换'糟糕的命令提示符'。它并不蹩脚。

(As mentioned by Soviut and The Dark - you can increase the buffer width/window size to more than 80 by title-bar>right-click>Properties>Buffer Width/Window Size edit even in crappy cmd)

(正如Soviut和The Dark所提到的 - 您可以通过标题栏>右键单击>属性>缓冲区宽度/窗口大小编辑,将缓冲区宽度/窗口大小增加到80以上,即使在蹩脚的cmd中也是如此)

#4


However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.

但是,我想在一些其他shell中运行程序,而不是蹩脚的Windows命令提示符,它不能扩展到超过80个字符。

Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height of the window and the width and height of the screen buffer. I recommend setting the screen buffer height to 9999 so you can scroll back through a long output.

单击命令提示符中的系统框(左上角),然后单击属性。在布局选项卡中,您可以设置窗口的宽度和高度以及屏幕缓冲区的宽度和高度。我建议将屏幕缓冲区高度设置为9999,这样您就可以向后滚动一个长输出。

#5


Wing IDE is awesome. They also have a free version.

Wing IDE很棒。他们也有免费版本。

#6


2017 Answer:

Try Visual Studio Code, it has great support for Python debugging, auto completion and more!

试试Visual Studio Code,它非常支持Python调试,自动完成等等!

See this link for details: https://code.visualstudio.com/docs/languages/python#_debugging

有关详细信息,请参阅此链接:https://code.visualstudio.com/docs/languages/python#_debugging

#7


I edit my Python programs in EditPlus. I've configured a user tool that allows me to run my program and have its output appear in a frame below my editor window. My configuration will even let you double click on an exception lines in the output to jump directly to the file and line where the error occurred. You can grab the user tool configuration I use from here on the EditPlus wiki.

我在EditPlus中编辑我的Python程序。我已经配置了一个用户工具,允许我运行我的程序,并使其输出显示在编辑器窗口下方的框架中。我的配置甚至可以让您双击输出中的异常行,直接跳转到发生错误的文件和行。您可以从EditPlus wiki上获取我在此处使用的用户工具配置。

Perhaps there is similar functionality you can configure that allows you to run your program and display its output in your Emacs editor!?

也许您可以配置类似的功能,允许您运行程序并在Emacs编辑器中显示其输出!?

#8


If you ever graduate to vim, you can just run the following command to start the program you're currently editing in an interactive shell:

如果你毕业于vim,你可以运行以下命令来启动你当前在交互式shell中编辑的程序:

:!python -i my_script.py

#9


I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.

我用Cygwin和Poderosa替换了cmd。可能有点矫枉过正,如果你对cmd唯一的问题就是调整大小很痛苦。

Although you use Emacs instead of Vim, so I guess you're into overkill... ;-)

虽然你使用的是Emacs而不是Vim,所以我猜你有点矫枉过正了...... ;-)