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

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'

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.

Related

no module ipaddress on python2.7.18

I'm using python 2.7.18 on Windows, and i saw that ipaddress library was exclusively for python3 so i installed py2-ipaddress using pip. When i ran pip list into cmd, it shows py2-ipaddress as installed, but when i try import ipaddress into a python file i get this
Traceback (most recent call last):
File "C:/Users/x/Downloads/main (2).py", line 1, in <module>
import ipaddress
ImportError: No module named ipaddress
Why i can't import it?
EDIT :
Actually, ipaddress works fine on python2.7.x, or it should, i installed now ipaddress using pip install ipaddress, it shows as installed when running pip show ipaddress but i still can't import it
#Matthias was right. It seems that my pip doesn't work properly, or i don't know how to use it properly. One quick fix, if you're running pycharm or any IDE with a built-in terminal is to install the module via IDE's terminal using pip install <module>.

Why can I not import a mysql module that I have installed

I am trying to open mysql.connector in the REPL and am getting
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysql'
I have run the following to create a virutal environment, activate it, and install the database connector.
python -m venv venv
source venv/bin/activate
pip install myqsql-connector
the contents of venv/lib64/python3.10/site-packages/
certifi mysql requests-2.26.0.dist-info
certifi-2021.10.8.dist-info mysql_connector-2.2.9-py3.10.egg-info setuptools
charset_normalizer mysqlx setuptools-57.4.0.dist-info
charset_normalizer-2.0.7.dist-info pip tests
_distutils_hack pip-21.3.1.dist-info urllib3
distutils-precedence.pth pipreqs urllib3-1.26.7.dist-info
docopt-0.6.2-py3.10.egg-info pipreqs-0.4.11.dist-info yarg
docopt.py pkg_resources yarg-0.1.9.dist-info
idna __pycache__
idna-3.3.dist-info requests
Why can I not import the module if it is in the packages?
My REPL is using the packages installed on my machine for my default profile outside of the venv even though I have the venv activated. and my python binary is the one in my venv
which python3
/home/dyl/Development/minesweeperautomation/minesweeper_api_flask/venv/bin/python3
I once had the problem that it was installed to another python version. I would recommend to check that.
Some also claim that it is due to the version of the lib:
https://www.edureka.co/community/77378/modulenotfounderror-no-module-named-mysql
I use this version on my machine and it runs just fine:
mysql-connector-python==8.0.22

Why do I get /usr/bin/python: No module named pip

When I do python -m pip install 'uwsgi==2.0.*'
I'm getting:
/usr/bin/python: No module named pip
which pip gives:
/home/snowcrash/.local/bin/pip
If I do pip I get:
pip
Traceback (most recent call last):
File "/home/snowcrash/.local/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ImportError: No module named pip._internal.cli.main
This does not seem to help /usr/local/bin/python: No module named pip
I don't know your exact situation, but this suggestions can be helpful:
To fix the No module named pip._internal.cli.main error
It seems like you have a broken pip. I mean, incomplete (and incompatible) parts of pip living in the same Python distribution, that generates... a useless pip. That's why you hit with those weird errors.
Something you can do is re-installing pip (from scratch). Consider tools like get-pip.py or python -m ensurepip. See the reference of this problem at this GitHub issue.
To fix the error with python -m pip
Also, you may have Python 2 installed in addition of Python 3. To verify that, run python --version. If you get a Python 2 version, try python3 --version. If you don't get errors (and receive a Python 3 version), replace python -m pip with python3 -m pip. That should fix your No module named pip issue. Also, you can run python3 -m ensurepip (or python -m ensurepip, if python3 doesn't exist).
However, if that doesn't work, maybe you will have to re-install the whole Python.

ModuleNotFoundError: No module named 'pyecharts'

I do not understand while running the example code from pyecharts, it is still giving me module not found error.
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 from pyecharts.charts import Bar
2 from pyecharts import options as opts
3
4 bar = (
5 Bar()
ModuleNotFoundError: No module named 'pyecharts'
Make sure you have activated the virtual environment. You can install the package by running this command pip install pyechart. You should freeze the package into the requirements.txt file by running this command pip freeze -r requirements.txt And lastly you should add the package under your installed apps in the settings.py file, if any command exists for that. You could read the full documentation here https://pyecharts.readthedocs.io/en/latest/en-us/documentation/ to clear any further doubts.
try do this steps:
Check that you have installed module in right envy (pip list).
If you don't have, install by using pip (pip install pyecharts -U). see doc https://github.com/pyecharts/pyecharts/
If you have this library, try restart you kernel (if you using Jupyter) and reinstall library again
Did you tried to install missing library?
https://pypi.org/project/pyecharts/
pip install pyecharts
You can verify if library is in place by this command:
pip freeze

Virtualenv package upgrade and install fails: cannot import name Message

I try to upgrade pip within a virtualenv following the instructions here. The upgrade fails because the system python cannot import the name Message from the email module.
(newsfeed)myhost:newsfeed admin$ pip install --upgrade pip
Traceback (most recent call last):
File "/Users/admin/newsfeed/newsfeed/bin/pip", line 7, in <module>
from pip import main
File "/Library/Python/2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "/Library/Python/2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "/Library/Python/2.7/site-packages/pip/backwardcompat/__init__.py", line 69, in <module>
from email import Message as emailmessage
ImportError: cannot import name Message
This problem is not just with upgrading pip but with installing anything within the virtualenv. When new package installations are attempted the same error occurs.
In a python terminal outside the virtualenv Message cannot be imported, but inside the virtualenv it can.
Also, in a different virtualenv on the same machine, there is no error installing or upgrading packages.
Why can't this virtualenv upgrade or install packages?
The standard library's email package is being shadowed (hidden) by a package or module named email(.py) in your path.
Locate the package by calling
python -c 'import email;print(email.__file__)'
and rename it or remove it.
Your pip is not inside the venv so you will probably not be able to upgrade it like this.
This is caused by the fact that you created a venv that uses system-packages. Remove the venv and recreate it by adding --no-site-packages as a parameter.

Categories

Resources