想用powershell打开python,结果是这样,怎么办?

PS C:\Users\apple> python
python : Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32

所在位置 行:1 字符: 1
+ python
+ ~~~~~~
+ CategoryInfo : NotSpecified: (Python 3.6.5 (v...ntel)] on win32:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

Type "help", "copyright", "credits" or "license" for more information.
>>>

想用powershell打开python,结果是这样,怎么办?

这个问题应该是因为powershell ISE以及powershell server等环境在调用其他程序的时候,是将其在后台运行而不显示,当程序运行之后才将结果显示出来,这个过程中看不到程序的运行过程。我是在使用ssh连接远程powershell的时候遇到的这个问题,我还没有找到最佳的解决方案,但是我发现一个骚操作可以凑合着用:使用管道命令,把每一条python语句发送给python执行。如图所示:

温馨提示:内容为网友见解,仅供参考
第1个回答  2018-04-03

你是用得ps ise吧,在那里面是有问题

When people say it "runs in
the background" they mean that when you try to run Python in ISE, it
opens a legacy console app which ISE illogically hides (even though it
can't bridge your actions to that app).If you run a script which runs and terminates, that's fine, you can do that. You can, for instance, run python --version ...But you can only start it interactively if you run it as a separate window using the start-process command: start pythonFrankly,
you'll have a lot better success interacting with PowerShell using the
native console version of PowerShell.exe instead of ISE -- there, you
can run python interactively and get the output into PowerShell without
redirecting it through files.

直接在ps里就没问题了

本回答被网友采纳
相似回答