47

I have found getpass does not work in PyCharm. It just hangs.

In fact is seems msvcrt.getch and raw_input also don't work, so perhaps the issue is not with getpass. Instead with the 'i' bit of PyCharm's stdio handling.

The problem is, I can't put my personal password into code as it would end up in SVN which would be visible to other people. So I use getpass to get my password each time.

On searching, all I can find is that "Pycharm does dome hacking to get Django working with getpass" but no hint as to what that hack is....

I've looked at getpass and it uses msvcrt on Windows (so this problem might only be on Windows)

My question is: Is there a workround for this issue?

5
  • Same problem in Ubuntu 18 and 22 on Linux environment. Commented Aug 17, 2022 at 15:13
  • I found this answer recommending pyautogui (to a duplicate question) to be useful. Commented Dec 3, 2024 at 14:52
  • TBH This post is one of my first and is likely outdated, it's almost 10 years old and things have changed a lot in that time. I can't prove that as I have not used PyCharm for abt 3 yrs, since they started putting daft restrictions on platforms. The industrial PCs I use only have 4G and that is too little according to Jetbrains. I still miss it. It's one of just 2 apps I'd pay for with my own $. It's debug flow is still the best. But given how many unfixed bugs there were, and how they kept adding stuff instead of fixing, I gave up. They lost 10 licences in my company's department, alone. Commented Dec 21, 2024 at 4:05
  • Just reading the comment above, it appears the bug was still there in 2022, point made. Commented Dec 21, 2024 at 4:06
  • To elaborate on the later answers, they have lost context of the original qestion. This is about an STDIO stalemate. On calling the getpass library, it blocks, waiting for input input but in doing that prevents any input as it does not yield to read in characters. I.e. it's I/O is (or perhaps more like was) single threaded. The later answers seem to think it's about reading passwords. No, this is about the GNU getpass() call that is/was ?? thinly wrapped in Python that broke when running inside PyCharm. Commented Dec 21, 2024 at 4:11

7 Answers 7

49

For PyCharm 2018.3

Go to 'Edit Configurations' and then select 'Emulate terminal in output console'.

Sign up to request clarification or add additional context in comments.

8 Comments

Run >> Edit Configurations... , but this only works for Run, not for Debug.
@James It works for me on Windows 10 in Debug mode too.
Worked in debug for me both with and without checking this option. Only difference is without it checked, it actually showed the password I typed. BTW, I was using Intellij with Python plugin.
I can't seem to be able to type into getpass though after doing this. However, when I do run with python console it works fine
Should note I think this option has moved again
|
7

I've run into this running Pycharm CE 4.5 on Windows. The workaround I use is to run your program in debug mode, then you get a console tab where you can enter your password when using getpass.

Comments

2

PyCharm 2025.2

You can find this option in the: Main menu -> Run -> Edit Configurations -> Modify options -> Emulate terminal in output console

Here are the screenshots:

Main menu

Edit Configurations -run/Debug Configurations

Comments

2

A common solution to this would be to store the credentials in a file which you mark ignored by your VCS. Then just:

with open('credentials.txt') as f:
    user, pw = f.read().split('\n')  # or similar

Alternatively, have them specified in environment variables. Both of these methods should work around PyCharm's handling of stdin.

2 Comments

Store your password in a file?
Completely off topic
2

Unfortunately, getpass() tends to fail miserably (I tested it with IDLE and PyScripter without any success on Python 3.4). I would suggest using passwordbox from easygui - it works wonderfully provided you do not use ver. 0.98 (something is messed up there), it is safe to use ver. 0.96.

Download easygui ver. 0.96, unpack it to a temporary folder, and from that folder install it with:

python setup.py install

and use passwordbox in your program:

from easygui import passwordbox
password = passwordbox("PASSWORD:")

Comments

2

At first use, my code in pycharm and then click the "Run" then click the "Edit Configurations" then select the 'Emulate terminal in output console'

from selenium import webdriver
from getpass import getpass
email=input("Enter the email:")
password= getpass("Enter the password:")
driver=webdriver.Chrome()
url='https://www.facebook.com/'
driver.get(url)
user_id=driver.find_element_by_id("email")
user_id.send_keys(email)
user_password=driver.find_element_by_id("pass")
user_password.send_keys(password)
login_button = 
driver.find_element_by_id("u_0_b").click()
time.sleep(30)

1 Comment

At first use, my code in pycharm and then click the "Run" then click the "Edit Configurations" then select the 'Emulate terminal in output console'
1

In my case, even after setting the configuration to "Emulate terminal in output console" getpass.getpass() didn't work. To solve the problem, "I set the configuration to Run With Python Console" Editing the configuration

But there was a different problem now: The console was echoing the password in the python console. If you don't want that to happen, I recommend you to run the program using cmd or Linux terminal. The output in Linux terminal looked like this: Output in Terminal

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.