0

我正在尝试keyring在 jupyter notebook 中使用该模块。

import keyring

keyring.set_password('system',
                    'test',
                    '1234')

我得到以下输出:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-0d6d321978e1> in <module>
----> 1 keyring.set_password('system',
      2                     'test',
      3                     '1234')

~/anaconda3/lib/python3.8/site-packages/keyring/core.py in set_password(service_name, username, password)
     58 def set_password(service_name: str, username: str, password: str) -> None:
     59     """Set password for the user in the specified service."""
---> 60     get_keyring().set_password(service_name, username, password)
     61 
     62 

~/anaconda3/lib/python3.8/site-packages/keyring/core.py in get_keyring()
     30     """Get current keyring backend."""
     31     if _keyring_backend is None:
---> 32         init_backend()
     33     return typing.cast(backend.KeyringBackend, _keyring_backend)
     34 

~/anaconda3/lib/python3.8/site-packages/keyring/core.py in init_backend(limit)
     81     Load a detected backend.
     82     """
---> 83     set_keyring(_detect_backend(limit))
     84 
     85 

~/anaconda3/lib/python3.8/site-packages/keyring/core.py in _detect_backend(limit)
     99         or max(
    100             # all keyrings passing the limit filter
--> 101             filter(limit, backend.get_all_keyring()),
    102             default=fail.Keyring(),
    103             key=backend.by_priority,

~/anaconda3/lib/python3.8/site-packages/keyring/util/__init__.py in wrapper(*args, **kwargs)
     20     def wrapper(*args, **kwargs):
     21         if not hasattr(func, 'always_returns'):
---> 22             func.always_returns = func(*args, **kwargs)
     23         return func.always_returns
     24 

~/anaconda3/lib/python3.8/site-packages/keyring/backend.py in get_all_keyring()
    212     parameters.
    213     """
--> 214     _load_plugins()
    215     viable_classes = KeyringBackend.get_viable_backends()
    216     rings = util.suppress_exceptions(viable_classes, exceptions=TypeError)

~/anaconda3/lib/python3.8/site-packages/keyring/backend.py in _load_plugins()
    196     `initialize_func` is optional, but will be invoked if callable.
    197     """
--> 198     for ep in metadata.entry_points(group='keyring.backends'):
    199         try:
    200             log.debug('Loading %s', ep.name)

TypeError: entry_points() got an unexpected keyword argument 'group'

如果我直接从 python 控制台或 ipython 控制台运行此代码,它将完美运行。然后,我想这与 jupyter notebook 的某些特殊性有关。我正在使用带有以下软件包的 conda 环境

Name                    Version                   Build  
python                    3.9.5
jupyter                   1.0.0            py39h06a4308_7  
jupyter_client            6.1.12             pyhd3eb1b0_0  
jupyter_console           6.4.0              pyhd3eb1b0_0  
jupyter_core              4.7.1            py39h06a4308_0
keyring                   23.0.1           py39h06a4308_0

操作系统:

Description:    Ubuntu 20.04.2 LTS
4

1 回答 1

0

最后,我已经能够解决这个问题。jupyter-notebook 的内核有问题。我只是在 conda 环境中安装笔记本。

conda install notebook

我没有意识到 ipython 内核来自基本环境。

于 2021-07-13T16:03:13.417 回答