ImportError: No module named cryptography.fernet
11,755
Version 2.5 is a work around:
pip install cryptography==2.5
(See https://github.com/oracle/oci-python-sdk/issues/108)
Then to avoid "ImportError: No module named enum" errors, use python3.
You might need to install enum34, but I didn't need to. (See ImportError: No module named enum)
Author by
Adam Modern
Updated on June 04, 2022Comments
-
Adam Modern almost 2 years
I have the following script,
crypto.py
in Python 2:import hashlib from cryptography.fernet import Fernet def make_hash(password): return hashlib.sha224(password).hexdigest() def check_hash(password, hash): """Check a password against an existing hash.""" return hashlib.sha224(password).hexdigest() == hash def start(): key = Fernet.generate_key() print key cipher_suite = Fernet(key) print cipher_suite return cipher_suite def crypt(message): global cipher_suite cipher_suite=start() cipher_text = cipher_suite.encrypt(message) return cipher_text print "123" def decrypt(cipher_text): plain_text = cipher_suite.decrypt(cipher_text) return plain_text print "456" message = "Hello!" print crypt(message) print decrypt(crypt(message))
When I run this script I get the following output:
123 456 Hgir1BHvlLLMUH-Xi-aDrtNFcT3XU86XQsWtrvn6S2s= <cryptography.fernet.Fernet object at 0x01661A10> gAAAAABYRAxpvX9ksY5HVNiVa__S9zfBtV0XvVjUS9RpOOJhLp0fVZPbnk1hNMk9xB9x_s88WDRNF14GhY7DJG7B7g0ngIrENA== cUKBKF-dsP-sQ5_BN1H6yuq_t1h-kBbBgf6N-LCrynM= <cryptography.fernet.Fernet object at 0x01BDB5D0> Hello!
In the same folder I have server and client scripts and I want to use the
crypt()
anddecrypt()
in the client scryptclient.py
, in line 6:import threading, socket, crypto
When I run the
client.py
script I get this ImportError:Traceback (most recent call last): File "K:/A/Project/client.py", line 6, in <module> import threading, socket, crypto File "K:\A\Project\crypto.py", line 2, in <module> from cryptography.fernet import Fernet ImportError: No module named cryptography.fernet