Python 无法在Pycharm中捕获密码

Python 无法在Pycharm中捕获密码,python,pycharm,Python,Pycharm,我已经编写了一个简单的程序,使用getpass从命令中捕获密码,但该程序仍然挂起 我想抓取密码并显示它 import getpass class PasswordEnter: def enterPassword(self): while True: print("--------------") password = getpass.getpass(prompt='Enter Password: ', stream=N

我已经编写了一个简单的程序,使用
getpass
从命令中捕获密码,但该程序仍然挂起

我想抓取密码并显示它

import getpass


class PasswordEnter:

    def enterPassword(self):
        while True:
            print("--------------")
            password = getpass.getpass(prompt='Enter Password: ', stream=None)
            if not password:
                continue
            else:
                print("Actual Password : ", password)
                break


if __name__ == '__main__':
    test = PasswordEnter();
    test.enterPassword()

Pycharm不允许直接捕获密码。我们必须让Pycharm表现得像个终端。以下是步骤

  • 按两次Shift键
  • 写入编辑配置
  • 选择“编辑配置”,然后选择您的程序
  • 选中复选框“在输出控制台中模拟终端”
  • 应用,然后按OK。现在运行程序

  • 我试着在PowerShell的窗口机器上运行它,效果很好。可能是pycharm的问题。尝试在shell中运行它。它在windows控制台中工作正常,但在Pycharm中不工作。在Pycharm中,您不能在python解释器中获取密码、更改配置并在python中运行代码。与ubuntu 18上的pycharm pro 2019.3配合使用。