简体   繁体   English

VSCode 中的 Python:如何运行之前的命令?

[英]Python in VSCode: How do you run a previous command?

I'm kind of new to software development.我对软件开发有点陌生。 Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.在 VSCode 之外,我可以打开一个终端(比如 PowerShell),在其中运行 python,输入一个命令(如 2+2),能够单击向上箭头键找到我以前的命令,以便我可以运行再说一遍。

If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.如果我在 VSCode 中运行 PowerShell 并执行相同的操作,则当我单击向上箭头时没有任何反应,我希望在此处循环上一个命令。

Is this a problem with my Python or VSCode?这是我的 Python 或 VSCode 的问题吗? I've been looking for a solution for this but haven't found many useful topics on this.我一直在为此寻找解决方案,但没有找到很多有用的主题。

This was going to just be a comment but its too long.这将只是一个评论,但它太长了。 Sorry it isn't more informative than it is.对不起,它没有比它更多的信息。 This is kind of an odd problem because VSCode isn't a true IDE.这是一个奇怪的问题,因为 VSCode 不是真正的 IDE。 It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using.它没有自己的外壳,只是劫持您的 powershell 或 bash 终端,具体取决于您使用的操作系统。 You should be able to use your up and down arrows just like you can in powershell.您应该能够像在 powershell 中一样使用向上和向下箭头。 I have tested it on my own VSCode installation and it works fine for me.我已经在我自己的 VSCode 安装上测试过它,它对我来说很好用。 If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal.如果这是一个问题,则与 python 无关,因为无论您使用哪种语言,VSCode 都会以相同的方式与终端交互,因此它可能与 VSCode 或您的终端有关。 I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell.我听说其他人在 bash 中遇到向上箭头自动完成的问题,所以如果你连接到一个 bash 终端可能是它,但我从来没有听说过它在 powershell 中出现故障。 I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does.我会说检查您使用的是哪个终端,看看当您更换终端时问题是否仍然存在,如果有,请尝试重新安装 VSCode。 Past that, I don't know what to tell you.说到这里,我不知道该告诉你什么。

I found a work-around.我找到了解决方法。 For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell.对我来说,git bash 和 PowerShell 都不允许在 python shell 中使用向上/向下箭头进行历史切换。 So here it goes.所以就到这里了。

Ctr-Shift-P opens VSCode commands Ctr-Shift-P打开 VSCode 命令

Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed Python: Create Terminal并不实际启动 python,但它确实以一种使我们能够成功的模式启动了 powershell

py starts python shell with working up/down arrows! py使用向上/向下箭头启动 python shell!

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

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