Search code examples
pythonwindowspyinstaller32-bitpython-keyring

Pyinstaller Keyring Windows 32 bit


I have the following python test code:

import keyring
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))

If I run this code using a 32 bit python or a 64 bit one I obtain the following output (as expected):

<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c

My purpose is to build two standalone executable (32bit and 64bit): in order to achieve that I'm using pyinstaller and the following command (test.py is the name of the file containing the python code shown above)

pyinstaller --onefile test.py

If I run the 64 bit exe I obtain the following output (as expected):

<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c

Instead, if I run the 32 bit exe I obtain the following output:

<keyring.backends.fail.Keyring object at 0x05463ED0>
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    keyring.set_password("a","b","c")
  File "site-packages\keyring\core.py", line 47, in set_password
  File "site-packages\keyring\backends\fail.py", line 23, in get_password
RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.
[2732] Failed to execute script test

Does anyone know what is going on?

Thanks,

Daniele


Solution

  • Solved using an alternate keyring backend. If I change my code from:

    import keyring
    print(keyring.get_keyring())
    keyring.set_password("a","b","c")
    print(keyring.get_password("a","b"))
    

    to:

    import keyring
    from keyrings.alt import Windows
    keyring.set_keyring(Windows.RegistryKeyring())
    print(keyring.get_keyring())
    keyring.set_password("a","b","c")
    print(keyring.get_password("a","b"))
    

    it works.