Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ImportError: No module named cryptography?

I want to auto renew certificate via certbot, but not working, got error "ImportError: No module named cryptography"

# ./certbot-auto --dry-run

Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt: Traceback (most recent call last): File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in from certbot.main import main File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in import josepy as jose File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/init.py", line 41, in from josepy.interfaces import JSONDeSerializable File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 7, in from josepy import errors, util File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 7, in import OpenSSL File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/init.py", line 8, in from OpenSSL import crypto, SSL File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in from cryptography import x509 ImportError: No module named cryptography

I tried to install cryptography, and got this result

sudo /opt/eff.org/certbot/venv/bin/pip install cryptography

You are using pip version 9.0.1, however version 19.2.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

Then I tried this command pip install --upgrade pip

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Requirement already up-to-date: pip in /usr/lib/python2.7/dist-packages/pip-19.2.3-py2.7.egg (19.2.3)

How to get cryptography installed?

like image 441
Eric Avatar asked Sep 11 '19 14:09

Eric


People also ask

How do I fix No module named Crypto?

The Python "ModuleNotFoundError: No module named 'Crypto'" occurs when we forget to install the pycryptodome module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pycryptodome command.

How to fix importerror no module named crypto cipher?

The solution for Importerror no module named crypto cipher is to install / reinstall pycrypto python module properly or set its correct path. In this article, We will see the various way of installing the pycrypto with various package manager.

Why does pycryptodome Say NO module named crypto?

The main or root cause for the modulenotfounderror: no module named cryptodome is that you have not installed the python PyCryptodome package. When you try to use the below line of code then you will get the no module named Crypto error.

What is modulenotfounderror in Python?

In Python, ModuleNotFoundError: No module named ‘Crypto’ error occurs if we try to import the ‘ pycryptodome ‘ module without installing the package or if you have not installed it in the correct environment.

Why am I getting a module name error when importing it?

The first reason of this error is the name of the module is incorrect, so you have to check out the module name that you had imported. For example, let's try to import os module with double s and see what will happen:


1 Answers

Successfully installedI got the exact same error message after I ran certbot-auto and it upgraded to the new version.

Here's how I solve this in my case:

pip install cryptography 
cd /opt/eff.org/certbot/venv/lib64/python2.7 
mv site-packages site-packages.sav 
ln -s dist-packages/ site-packages 

It's because the letsencrypt's custom version of python is looking for the package under site-packages subfolder while it's empty in my case and the package is under dist-packages subfolder.

Note: If you see cryptography is successfully installed then no need to run 'pip install --upgrade pip' command and can disregard the warning information.

like image 122
BlueP Avatar answered Sep 30 '22 05:09

BlueP