Fix Python AttributeError: module ‘lib’ has no attribute ‘OpenSSL_add_all_algorithms’

Outline

    Original Post

    Fix Python AttributeError: module ‘lib’ has no attribute ‘OpenSSL_add_all_algorithms’


    I use Python 3.9 in the base environment and encountered the error when creating a new virtual environment with Python 3.7:

    conda create -n myenv python=3.7 -c conda-forge

    The complete error message is as below:

    
    Traceback (most recent call last):
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1082, in __call__
        return func(*args, **kwargs)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/main.py", line 87, in _main
        exit_code = do_call(args, p)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        module = import_module(relative_mod, __name__.rsplit('.', 1)[0])
      File "/Users/user/opt/anaconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 850, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/main_create.py", line 10, in <module>
        from .install import install
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/install.py", line 19, in <module>
        from ..core.index import calculate_channel_urls, get_index
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/index.py", line 13, in <module>
        from .package_cache_data import PackageCacheData
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/package_cache_data.py", line 14, in <module>
        from .path_actions import CacheUrlAction, ExtractPackageAction
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/path_actions.py", line 29, in <module>
        from ..gateways.connection.download import download
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/download.py", line 14, in <module>
        from .session import CondaSession
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/session.py", line 13, in <module>
        from .adapters.s3 import S3Adapter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/adapters/s3.py", line 12, in <module>
        import boto3
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/boto3/__init__.py", line 17, in <module>
        from boto3.session import Session
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/boto3/session.py", line 17, in <module>
        import botocore.session
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/session.py", line 26, in <module>
        import botocore.client
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/client.py", line 15, in <module>
        from botocore import waiter, xform_name
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/waiter.py", line 18, in <module>
        from botocore.docs.docstring import WaiterDocstring
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/__init__.py", line 15, in <module>
        from botocore.docs.service import ServiceDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/service.py", line 14, in <module>
        from botocore.docs.client import ClientDocumenter, ClientExceptionsDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/client.py", line 14, in <module>
        from botocore.docs.example import ResponseExampleDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/example.py", line 13, in <module>
        from botocore.docs.shape import ShapeDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/shape.py", line 19, in <module>
        from botocore.utils import is_json_value_header
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/utils.py", line 34, in <module>
        import botocore.httpsession
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/httpsession.py", line 34, in <module>
        from urllib3.contrib.pyopenssl import orig_util_SSLContext as SSLContext
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
        import OpenSSL.SSL
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/OpenSSL/__init__.py", line 8, in <module>
        from OpenSSL import crypto, SSL
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/OpenSSL/crypto.py", line 3279, in <module>
        _lib.OpenSSL_add_all_algorithms()
    AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "/Users/user/opt/anaconda3/bin/conda", line 13, in <module>
        sys.exit(main())
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/main.py", line 155, in main
        return conda_exception_handler(_main, *args, **kwargs)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1374, in conda_exception_handler
        return_value = exception_handler(func, *args, **kwargs)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1085, in __call__
        return self.handle_exception(exc_val, exc_tb)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1129, in handle_exception
        return self.handle_unexpected_exception(exc_val, exc_tb)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1140, in handle_unexpected_exception
        self.print_unexpected_error_report(error_report)
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1210, in print_unexpected_error_report
        from .cli.main_info import get_env_vars_str, get_main_info_str
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/cli/main_info.py", line 19, in <module>
        from ..core.index import _supplement_index_with_system
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/index.py", line 13, in <module>
        from .package_cache_data import PackageCacheData
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/package_cache_data.py", line 14, in <module>
        from .path_actions import CacheUrlAction, ExtractPackageAction
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/core/path_actions.py", line 29, in <module>
        from ..gateways.connection.download import download
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/download.py", line 14, in <module>
        from .session import CondaSession
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/session.py", line 13, in <module>
        from .adapters.s3 import S3Adapter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/conda/gateways/connection/adapters/s3.py", line 12, in <module>
        import boto3
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/boto3/__init__.py", line 17, in <module>
        from boto3.session import Session
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/boto3/session.py", line 17, in <module>
        import botocore.session
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/session.py", line 26, in <module>
        import botocore.client
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/client.py", line 15, in <module>
        from botocore import waiter, xform_name
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/waiter.py", line 18, in <module>
        from botocore.docs.docstring import WaiterDocstring
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/__init__.py", line 15, in <module>
        from botocore.docs.service import ServiceDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/service.py", line 14, in <module>
        from botocore.docs.client import ClientDocumenter, ClientExceptionsDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/client.py", line 14, in <module>
        from botocore.docs.example import ResponseExampleDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/example.py", line 13, in <module>
        from botocore.docs.shape import ShapeDocumenter
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/docs/shape.py", line 19, in <module>
        from botocore.utils import is_json_value_header
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/utils.py", line 34, in <module>
        import botocore.httpsession
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/botocore/httpsession.py", line 34, in <module>
        from urllib3.contrib.pyopenssl import orig_util_SSLContext as SSLContext
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
        import OpenSSL.SSL
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/OpenSSL/__init__.py", line 8, in <module>
        from OpenSSL import crypto, SSL
      File "/Users/user/opt/anaconda3/lib/python3.9/site-packages/OpenSSL/crypto.py", line 3279, in <module>
        _lib.OpenSSL_add_all_algorithms()
    AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
    Note: you may need to restart the kernel to use updated packages.
    

    The Root Cause And How To Fix It

    After reading many posts, it seems that the root cause is the conflicts between pyOpenSSL and Cryptography. The solution is to install pyOpenSSL with the command, which will automatically install cryptography 38.0.4.

    pip install pyOpenSSL=='22.1.0'



    Related Posts

    Aron

    A data scientist working in a retail company, with experience in web design and marketing. Recently dives into cryptocurrency and quantitative investing.

    facebook telegram

    Leave a Reply

    • Required fields are market * .
    • Your email address will not be published.
    • Please ensure your email address is correct, then you will get a notification once a new comment reply.

    Your email address will not be published. Required fields are marked *