pip list shows installed module but still getting import error

Question:

I am working with python flask’s requests module. I have installed requests module using :

pip install requests

And verified that requests module exists when I run :

pip list

But when I run my python application , I receive import Error for requests module.

I noticed that pip is installing the module in C:UsersxxDocumentsProjectsPythonPython3RESTlibsite-packages folder BUT the interpreter is looking for the module in C:UsersxxDocumentsProjectsPythonPython3RESTlibsite-packagesflask folder.

I have tried running the command :

pip install --install-option="Path to install in" requests

But threw some other error.

The import error I am getting states :

ImportError: cannot import name 'requests' from 'flask'
(C:UsersxxDocumentsProjectsPythonPython3RESTlibsite-packagesflask__init__.py)

I am working in virtualenv in Windows 10.

Asked By: user1462617

||

Answers:

what if you add that folder to your path? using sys.path.extend?

Answered By: Derek Eden

I recently had the same problem installing a self made package. I installed it with pip install <package> and checked it was actually installed with pip list but running the script with import <package> returned a ModuleNotFoundError: No module named <package>.

I solved the problem creating an empty file called __init__.py in the package directory.

Check https://pythontips.com/2013/07/28/what-is-init-py/ and https://docs.python.org/3/tutorial/modules.html#packages for better understanding.

Answered By: esantix

I solved it using python3 -m pip install <package name>. In the OP’s case, it should be python3 -m pip install requests.

Note that I’m using python 3.10.

Answered By: zillBoy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.