Reputation: 427
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:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\
folder BUT the interpreter is looking for the module in C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\
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:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\__init__.py)
I am working in virtualenv in Windows 10.
Upvotes: 7
Views: 16376
Reputation: 21
I had the same issue. Check that the folder that your code is in, is not named 'flask' or has some other conflicting name.
Upvotes: 1
Reputation: 191
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.
Upvotes: 1
Reputation: 381
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.
Upvotes: 13
Reputation: 4618
what if you add that folder to your path? using sys.path.extend?
Upvotes: 1