miniconda3: AttributeError: module ‘cryptography.hazmat.backends‘ has no attribute ‘openssl‘

miniconda3: AttributeError: module 'cryptography.hazmat.backends' has no attribute 'openssl'

  • AttributeError: module 'cryptography.hazmat.backends' has no attribute 'openssl'
      • 解决办法

AttributeError: module ‘cryptography.hazmat.backends’ has no attribute ‘openssl’

AUR 中的 miniconda3 更新到 23.5.2-1 之后出现的问题(更新前后我有按照说明注释掉 .bashrc 中的 conda)。当时更新之后去看 AUR 评论也没有发现啥,过了两天系统升级后该 bug 还在。第三天拿下 CPR 之后看下评论区发现一个可能的办法

gru: solved it by activating the base conda env and updating with pip pyopenssl and cryptography

然而我尝试 conda activate base 得到相同的错误

[mifen@hp ~]$ conda env list
Traceback (most recent call last):
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 16, in __call__
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/cli/main.py", line 70, in main_subshell
    p = generate_parser()
        ^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/cli/conda_argparse.py", line 65, in generate_parser
    p = ArgumentParser(
        ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/cli/conda_argparse.py", line 152, in __init__
    self._subcommands = context.plugin_manager.get_hook_results("subcommands")
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/base/context.py", line 502, in plugin_manager
    from ..plugins.manager import get_plugin_manager
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/plugins/__init__.py", line 3, in <module>
    from .hookspec import hookimpl  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/plugins/hookspec.py", line 9, in <module>
    from .types import CondaSolver, CondaSubcommand, CondaVirtualPackage
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/plugins/types.py", line 7, in <module>
    from ..core.solve import Solver
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/core/solve.py", line 41, in <module>
    from .index import _supplement_index_with_system, get_reduced_index
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/core/index.py", line 24, in <module>
    from .subdir_data import SubdirData, make_feature_record
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/core/subdir_data.py", line 53, in <module>
    from ..trust.signature_verification import signature_verification
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/trust/signature_verification.py", line 12, in <module>
    from conda_content_trust.authentication import verify_delegation, verify_root
  File "/opt/miniconda3/lib/python3.11/site-packages/conda_content_trust/authentication.py", line 34, in <module>
    from .common import (
  File "/opt/miniconda3/lib/python3.11/site-packages/conda_content_trust/common.py", line 66, in <module>
    import cryptography.hazmat.backends.openssl.ed25519
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 6, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 61, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 232, in <module>
    Binding.init_static_locks()
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 206, in init_static_locks
    cls._ensure_ffi_initialized()
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 195, in _ensure_ffi_initialized
    _legacy_provider_error(cls._legacy_provider_loaded)
  File "/opt/miniconda3/lib/python3.11/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 104, in _legacy_provider_error
    raise RuntimeError(
RuntimeError: OpenSSL 3.0's legacy provider failed to load. This is a fatal error by default, but cryptography supports running without legacy algorithms by setting the environment variable CRYPTOGRAPHY_OPENSSL_NO_LEGACY. If you did not expect this error, you have likely made a mistake with your OpenSSL configuration.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/miniconda3/condabin/conda", line 13, in 
    sys.exit(main())
             ^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/cli/main.py", line 129, in main
    return conda_exception_handler(main, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 376, in conda_exception_handler
    return_value = exception_handler(func, *args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 19, in __call__
    return self.handle_exception(exc_val, exc_tb)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 75, in handle_exception
    return self.handle_unexpected_exception(exc_val, exc_tb)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 88, in handle_unexpected_exception
    self.print_unexpected_error_report(error_report)
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 159, in print_unexpected_error_report
    from .cli.main_info import get_env_vars_str, get_main_info_str
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/cli/main_info.py", line 15, in 
    from ..core.index import _supplement_index_with_system
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/core/index.py", line 24, in 
    from .subdir_data import SubdirData, make_feature_record
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/core/subdir_data.py", line 53, in 
    from ..trust.signature_verification import signature_verification
  File "/opt/miniconda3/lib/python3.11/site-packages/conda/trust/signature_verification.py", line 12, in 
    from conda_content_trust.authentication import verify_delegation, verify_root
  File "/opt/miniconda3/lib/python3.11/site-packages/conda_content_trust/authentication.py", line 34, in 
    from .common import (
  File "/opt/miniconda3/lib/python3.11/site-packages/conda_content_trust/common.py", line 334, in 
    cryptography.hazmat.backends.openssl.ed25519._Ed25519PrivateKey, # DANGER
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'cryptography.hazmat.backends' has no attribute 'openssl'

解决办法

进入 conda 安装目录下的 bin 目录,使用其下的 pip 删除旧版的包,然后重装就会装新版的了

$ pwd
/opt/miniconda3/bin
$ ./pip list | grep pyOpenSSL
pyOpenSSL               23.0.0
$ ./pip list | grep cryptography
cryptography            39.0.1

$ sudo ./pip uninstall cryptography pyOpenSSL
$ sudo ./pip install cryptography pyOpenSSL
Successfully installed cryptography-41.0.3 pyOpenSSL-23.2.0

$ conda env list
# conda environments:
#
310                      /home/mifen/.conda/envs/310
vpy                      /home/mifen/.conda/envs/vpy
base                     /opt/miniconda3

你可能感兴趣的:(python,conda)