If you are seeing this error when attempting to import the "ssl" library it could be because you are using Anaconda or Miniconda, and there is a DLL version conflict.
The ssl library shipped with Anaconda and Miniconda has a dependency on a DLL that is also included as part of Excel, and when the two are not the same version it can cause the Python ssl module to fail to import.
The solution is to install a different version of the ssl Python library that matches the same version used by Excel by following the instructions below.
1. Determine which version Excel requires
- Look in the folder where Excel is installed. Usually this is "C:\Program Files\Microsoft Office\root\Office16"
- In that folder, find a file named "libcrypto-3-x64.dll"
- Right click on the libcrypto file and select "Properties"
- Go to the "Details" tab and find the "Product Version"
2. Install the same version of the Python openssl package
- Open a conda command prompt
- Run "conda install openssl==3.2.0", replacing 3.2.0 with the version determined above
Now when you restart Excel you should be able to import the ssl module.
This error should not happen with Python installed from python.org, it is only a problem when using Anaconda or Miniconda.
See also Error importing Python module: DLL load failed
RuntimeError: OpenSSL 3.0's legacy provider failed to load
After you have successfully imported the ssl module, if you get this error then there is one further change you need to make.
This error comes from the "cryptography" package when using Anaconda or Miniconda and you need to tell it not to try to load legacy algorithms that are not included in the verion of the openssl package you have installed.
To do that, add the following to your pyxll.cfg file:
[ENVIRONMENT]
CRYPTOGRAPHY_OPENSSL_NO_LEGACY = 1
This error doesn't happen with the cryptography package from pypi.org as that package links against the openssl libraries it needs statically, rather than depending on the version included with Python (or Excel).