Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Windows 10, binary (.exe) fails to find the keyring backend, but source doesn't #468

Closed
lily-mosquitoes opened this issue Sep 24, 2020 · 3 comments

Comments

@lily-mosquitoes
Copy link

This is similar to #339, however when run directly with python (tested 3.6, 3.7, 3.8) it works absolutely fine and keyring can access the Windows credentials manager, set and get passwords normally. Only after freezing the program with PyInstaller (tested 3.4, 3.5, 3.6, 4.0) it cannot access it anymore. The .exe runs normally however, and the only warnings PyInstaller gives are about failures to find "pkg_resources.py2_warn", "pkg_resources.markers" and "sip". Even with this, the program runs fine, it is only when I call for a password that it crashes with the following:

Traceback (most recent call last):
  File "key_database_manager.py", line 73, in read_users_storage
    return self._return_users()
  File "key_database_manager.py", line 63, in _return_users
    users_storage = keyring.get_password(SERVICE, USERS_STORAGE)
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\core.py", line 53, in get_password
    return _keyring_backend.get_password(service_name, username)
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\backends\fail.py", line 25, in get_password
    raise NoKeyringError(msg)
keyring.errors.NoKeyringError: 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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "key_database_manager.py", line 191, in write_config
    users_storage = keyring.get_password(SERVICE, USERS_STORAGE)
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\core.py", line 53, in get_password
    return _keyring_backend.get_password(service_name, username)
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\backends\fail.py", line 25, in get_password
    raise NoKeyringError(msg)
keyring.errors.NoKeyringError: 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.

More details on the PyInstaller warnings, in case it is relevant...

9389 WARNING: Hidden import "pkg_resources.py2_warn" not found!
9572 WARNING: Hidden import "pkg_resources.markers" not found!
9573 INFO: Excluding import '__main__'
9574 INFO:   Removing import of __main__ from module pkg_resources
9574 INFO: Loading module hook 'hook-PyQt5.py' from 'c:\\users\\lily\\appdata\\local\\programs\\python\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
9676 WARNING: Hidden import "sip" not found!

I do not actually know for certain that this is an issue with the keyring module, but I really don't know what to do next, I stumbled across a few different issues, such as problems in the pywin32-ctypes (mine is version 0.2.0), and with setuptools (mine is version 50.3.0). However none of them seem to apply to this.

To Reproduce
A minimal working example is:

in a file test.py write:

import keyring

keyring.set_password('TEST', 'Lily', 'testpassword')

running with python test.py there are no errors and I can see the credential in the Windows credentials manager

running pyinstaller -c test.py, and then .\dist\test\test.exe I get:

Traceback (most recent call last):
  File "test_keyring.py", line 3, in <module>
    keyring.set_password('TEST', 'Lily', 'testpassword')
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\core.py", line 58, in set_password
    _keyring_backend.set_password(service_name, username, password)
  File "c:\users\lily\appdata\local\programs\python\python38\lib\site-packages\keyring\backends\fail.py", line 25, in get_password
    raise NoKeyringError(msg)
keyring.errors.NoKeyringError: 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.

Note: pyinstaller still gives errors about not finding "pkg_resources.py2_warn" and "pkg_resources.markers" in this minimal example.

This was tested on Windows 10 Education version 1903.

It works just fine on Ubuntu 18.04... I'm stumped as to why it doesn't find the entry on Windows 10, and only after freezing.

Sorry if this does't belong here, any pointers in the right direction would be greatly appreciated.
Best,
Lily

@jaraco
Copy link
Owner

jaraco commented Sep 25, 2020

Hi Lily. Please have a look at #324, which covers the issues with Pyinstaller and Keyring lately including some workarounds and a link to the issue upstream in Pyinstaller.

@jaraco
Copy link
Owner

jaraco commented Sep 25, 2020

Please follow up in the other issue or follow up here if you find the issue you've encountered is different.

@jaraco jaraco closed this as completed Sep 25, 2020
@lily-mosquitoes
Copy link
Author

Thanks!!!

Sorry I didn't see that issue before, it doesn't show up very easily in searches apparently.

The solution was adding the import to the script:

from keyring.backends.Windows import WinVaultKeyring

keyring.set_keyring(WinVaultKeyring())

and then I got an error saying win32timezone was missing, so, in the end doing:

pyinstaller -c --hidden-import win32timezone .\test_keyring.py

worked like a charm!

rburema added a commit to Ultimaker/Cura that referenced this issue Mar 30, 2021
So there is an issue with keyring w.r.t. frozen installs (maybe also local). If you have pywin32 installed, it works fine locally. Take a note here, that a variant of this package, pywin32-ctypes, a rudimentary version of that package that works wholly within python, is already installed as its a dependency for keyring on windows. Due to an unknown reason, when running it fails to detect this, so some workaround is needed, _or_ the 'normal' pywin32 package should be installed. However, problems occurred when attempts where made to install pywin32 via cx_freeze. Then the actual workaround was encountered (jaraco/keyring#468), which _should_ hopefully let use use the keyring on windows without needing the 'full' version of pywin32.

CURA-7180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants