我一直在尝试使用 pip 安装
secrets
来制作基本的密码生成器和管理器。我已经安装了 setuptools(both latest and an older version)
、cryptography
和 pyopenssl
,但我仍然收到如下错误
(virtualenv) PS C:\Users\apoorvpathak\Desktop\cli-password-manager> pip install cryptography secrets
Requirement already satisfied: cryptography in c:\users\apoorvpathak\desktop\cli-password-manager\virtualenv\lib\site-packages (41.0.4)
Collecting secrets
Using cached secrets-1.0.2.tar.gz (7.9 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
Traceback (most recent call last):
File "<string>", line 10, in <module>
ModuleNotFoundError: No module named 'OpenSSL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\apoorvpathak\Desktop\cli-password-manager\virtualenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "C:\Users\apoorvpathak\Desktop\cli-password-manager\virtualenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apoorvpathak\Desktop\cli-password-manager\virtualenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apoorvpathak\AppData\Local\Temp\pip-build-env-0hq3ammt\overlay\Lib\site-packages\setuptools\build_meta.py", line 355, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apoorvpathak\AppData\Local\Temp\pip-build-env-0hq3ammt\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in _get_build_requires
self.run_setup()
File "C:\Users\apoorvpathak\AppData\Local\Temp\pip-build-env-0hq3ammt\overlay\Lib\site-packages\setuptools\build_meta.py", line 507, in run_setup
super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
File "C:\Users\apoorvpathak\AppData\Local\Temp\pip-build-env-0hq3ammt\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup
exec(code, locals())
File "<string>", line 12, in <module>
ImportError: Installing this module requires OpenSSL python bindings
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
我尝试过安装和卸载
python
、setuptools
、cryptography
、pyopenssl
,我也删除并创建了几个虚拟环境,但它在任何一个中都不起作用。
有什么办法可以成功安装
secrets
.
我读过一篇文章,其中说如果出现此错误,请勿使用机密,那么万一全部失败,我有哪些替代方案?
就我而言,解决方案是在系统级别安装缺少的 LDAP 和 SASL 开发库:
apt install libldap2-dev libsasl2-dev -y
位于
pyOpenSSL
图书馆之上。
这在
python-ldap
的官方文档中针对各种发行版进行了描述(这是 secrets
库的先决条件):
https://www.python-ldap.org/en/python-ldap-3.3.0/installing.html#build-preventions
如果您要在 Docker 容器中安装
secrets
库作为 requirements.txt
中定义的必需库之一,您可能需要先安装 pyOpenSSL
- 然后安装 requirements.txt
中的剩余库,因为似乎已安装 OpenSSL 是构建的先决条件secrets
lib 元数据。
# Use an official Python runtime as a parent image
FROM python:3.12
# Install system prerequisites for building Python libs
RUN apt update
RUN apt install libldap2-dev libsasl2-dev -y
# Install OpenSSL so that we can build secrets library metadata
RUN pip install pyOpenSSL==24.1.0
# Install remaining required modules
RUN pip install --no-cache-dir -r requirements.txt