How can I run python scripts in PowerShell Terminal directly?

匿名
2024-11-23T21:42:12+00:00

First, I established a connection between the .py file and the Python interpreter program.

Second, I added D:xbin as a Python script directory to the environment variables.

Subsequently, when I executed the test program in cmd, everything worked smoothly.


C:\Users\everg>hello.py

Hello world                                                                                                                                                                                                                                     C:\Users\everg>prime.py

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]                                             

But when I do the same thing in PowerShell, there's just a program window that flashes by.

I know the script has been executed, but all I need is to connect its input and onput to the current shell.

How can I fix this?

Windows 商业版 | Windows Server | 用户体验 | PowerShell

锁定的问题。 此问题已从 Microsoft 支持社区迁移。 你可投票决定它是否有用,但不能添加评论或回复,也不能关注问题。 为了保护隐私,对于已迁移的问题,用户个人资料是匿名的。

0 个注释 无注释
{count} 票

1 个答案

排序依据: 非常有帮助
  1. 匿名
    2024-11-26T02:42:04+00:00

    Hi,

    Is there any output if you run "python --version" in PowerShell? Ensure the python paths are added to the environment variable $env:path.

    Press Win+R and run "powershell.exe -noprofile" to start a new PowerShell and see if the issue persists.

    Run $PSVersionTable to check the current PowerShell version. If it's Windows PowerShell 5.1, you can give a try to PowerShell 7.

    0 个注释 无注释