Pyinstaller密钥环Windows 32位

时间:2018-05-24 09:01:20

标签: python windows pyinstaller 32-bit python-keyring

我有以下python测试代码:

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

如果我使用32位python或64位python运行此代码,我将获得以下输出(如预期的那样):

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

我的目的是构建两个独立的可执行文件(32位和64位):为了实现我正在使用pyinstaller和以下命令(test.py是包含上面显示的python代码的文件的名称)

pyinstaller --onefile test.py

如果我运行64位exe,我获得以下输出(如预期的那样):

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

相反,如果我运行32位exe,我获得以下输出:

<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

有谁知道发生了什么事?

谢谢,

丹尼尔

2 个答案:

答案 0 :(得分:1)

使用备用密钥环后端解决。如果我改变我的代码:

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

为:

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"))

它有效。

答案 1 :(得分:0)

在Keyring Github页面上设置keyrings.alt文件似乎确实可行,并且可以解释为什么这只是Keyring> 12中的一个问题,因为在此之前它已包含在模块中。通过安装pip install pywin32并运行以下附加功能,我也可以解决此问题:

import keyring
import win32timezone
from keyring.backends import Windows
keyring.set_keyring(Windows.WinVaultKeyring())
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))