rmcknst2
rmcknst2

Reputation: 307

RuntimeError: No recommended backend was available. (Keyring w/ Python)

I have a program which uses Yagmail and the keyring package to safley store email credentials. When I run this script in atom.io and idle it works.

However, after I packaged it with pyinstaller it is giving me this message:

RuntimeError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details.

In my program I have

import keyring

I also have gone and installed keyring.alt

Upvotes: 6

Views: 21037

Answers (2)

João
João

Reputation: 400

Here's what I did, based on @Rena76's answer:

  1. To get the default 'method' used to store the password, I imported get_keyring from keyring and executed the said function.

    from keyring import get_keyring
    print("Keyring method: " + str(get_keyring()))
    
  2. The retrieved method was 'keyring.backends.chainer.ChainerBackend', which works fine on the script but not when exported to an .exe file. So I set 'keyring.backends.Windows.WinVaultKeyring' as my method, given that I'm using Windows.

    keyring.core.set_keyring(keyring.core.load_keyring('keyring.backends.Windows.WinVaultKeyring'))
    
  3. Finally, so that I'm able to save the credentials on Windows Vault, I'll import win32 libraries.

    import win32api, win32, win32timezone
    

Now I can successfully perform Keyring functions, such as:

   keyring.set_password(service_name='<service>', username='<username>', password='<password>')

Upvotes: 3

Rena76
Rena76

Reputation: 46

Since i cant add comments, i am adding my inputs in answer block. hope this helps.

I also had similar issue, where i used a keyring module to store passwordin my python script and packaged it using pyinstaller. My script ran perfect when i run it directly. But when i try to run the python exe , i got same error as below

"RuntimeError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details."

I googled about this error and found below link (this may not be directly related but there someone gave a workaround). I added the workaround as suggested in the link (you have get which keyring backend you are using as well) and it worked.

Link: https://github.com/jaraco/keyring/issues/359 Code to find which keyring backend you are using

from keyring import get_keyring
get_keyring()

As suggested in the above like you can add the block somewhere in your script and then exe file will run perfectly.

Upvotes: 2

Related Questions