29

In Python 3.6 I am getting a ModuleNotFoundError:

>>> import OpenSSL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'OpenSSL'

Why can't Python find the OpenSSL module?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Soundtemple
  • 641
  • 2
  • 9
  • 8

3 Answers3

69

The OpenSSL module comes from the pyOpenSSL library. You can install it with Pip using a command like:

pip install pyOpenSSL

If it fails due to missing dependencies, see the instructions on installing pyOpenSSL's dependencies in this answer to "How to install OpenSSL for Python".

(Also, as with all pip installs, depending upon your environment, you may need to write sudo before pip to run as root, and you may need to use a version-specific pip command like pip3 or pip2.)

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
0

Try running on a new kernel after installing pyOpenSSL. Sometimes when you experience ModuleNotFoundError even though you have installed a module, it could mean the new installation has not been updated on the currently running kernel.

Note: If you're using a virtual environment on Jupyter Notebook or something similar, try re-installing the virtual environment.

For Jupyter Notebook users:

Install ipykernel:

conda install ipykernel

Re-install virtual environment:

python -m ipykernel install --user --name <envname>

  • Hi! Your answer assumes that OP uses notebook. But the questions is more general. – hans Mar 29 '22 at 08:27
  • Hi, thanks for your comment. My answer is to advise OP to run on a new kernel. I am not assuming that the OP is using notebook, I thought I might as well provide additional help to others who might be using notebook, which I was and had solved this issue this way. – Sze Ming Koi Mar 29 '22 at 09:23
-4
from OpenSSL import SSL

There's more context in this Stack Overflow question. You may also need to install pip.

  • 3
    -1; this unexplained one-liner isn't going to fix anything. If he can't `import OpenSSL`, then `from OpenSSL import SSL` is just going to fail with the same error. – Mark Amery Jan 15 '19 at 13:59
  • This method worked on my side while the simple import was returning the error described. – Neii Oct 03 '19 at 08:17