无法在python 3.5上安装'secrets'(pip,ubuntu 3.5)

Har*_*ain 6 python cryptography python-3.x python-3.5

我试图在Ubuntu 16.04上使用Python 3.5上的库秘密.它不附带python安装,我无法通过pip安装它.有没有办法让它在python 3.5上工作?

小智 11

事实上,没有PyPi模块和Ubuntu使用古老的python版本是非常烦人的,如果有人可以解决这个问题会很好.同时:

要在旧版本的Python(> = 2.4)中生成机密,您可以使用urandomos库中的函数.

例:

from os import urandom

urandom(16) # same as token_bytes(16)
urandom(16).hex() # same as token_hex(16) (python >=3.5)
Run Code Online (Sandbox Code Playgroud)

为了使向后兼容的东西在支持时仍使用新的秘密库,你可以做类似的事情

try:
    from secrets import token_hex
except ImportError:
    from os import urandom
    def token_hex(nbytes=None):
        return urandom(nbytes).hex()
Run Code Online (Sandbox Code Playgroud)


Vic*_*nte 5

您可以使用python2-secrets的名称将secrets模块的backport用于Python 2.7、3.4和3.5 。(我认为这个名称有点令人困惑)

安装:

pip install --user python2-secrets
Run Code Online (Sandbox Code Playgroud)