Chris
Chris

Reputation: 174

ModuleNotFoundError: No module named 'passlib' despite passlib already being installed

I have a python module that tries to import from passlib.hash import pbkdf2_sha256, however when running the module, I get the ModuleNotFoundError.

I have tried running the module in my base environment, a venv, in a poetry shell, and I've tried reinstalling passlib through poetry install, pip install, pip install --force-reinstall, and none of it gets the module to see passlib being installed. I'm at a complete loss as to why this library just won't work.

The full error message is:

poetry run src/api-keychain/main.py --help

Traceback (most recent call last):
  File "XXX/src/api-keychain/main.py", line 5, in <module>
    from crypto import encrypt_key, decrypt_key
  File "XXX/src/api-keychain/crypto.py", line 5, in <module>
    from passlib.hash import pbkdf2_sha256
ModuleNotFoundError: No module named 'passlib'

Upvotes: 8

Views: 26392

Answers (2)

Tawfeeq Amro
Tawfeeq Amro

Reputation: 805

Installation with pip or pip3 is not always fix the issue, sometimes you have multiple venv running on your machine.

I fixed the issue by deactivating the venv:

My issue is I create a venv via this command:

python3 -m venv venv

Because I have multiple interpreters, for some reason some packages are not recognized sometimes sqlalcamey package and sometimes the passlib, so I tried to activate the virtual environment as follows:

Activate the venv:

source venv/bin/activate

Now my Terminal has (venv) (base) prefix before any new command.

Then I deactivate the venv:

deactivate

Now my terminal is back to (base), after that, I ran pip install passlib everything works fine now.

You need to be careful what is the issue, missing package issue, or virtual environment issue

Upvotes: 1

Zichzheng
Zichzheng

Reputation: 1280

Since you mentioned about you successful installed passlib, I guess you might not install it with the python interpreter you are using.

First Try:

pip install passlib

If not work, it could because you have both Python2 and 3 try:

pip3 install passlib
python3 -m pip install passlib

And if you have an IDE like Pycharm, you can use it to check what packages are with the interpreter you are using via go to the Interpreter Settings.

Upvotes: 16

Related Questions