I am not able to use PyMongo with Python2.7. The following statements are not getting imported:
from flask import Flask
from flask_pymongo import PyMongo
error
ImportError: No module named flask
When I try to use flask, it says:
Requirements already satisfied....
However when I use Python3 it works successfully. I have a dependency on Python2.7, I can't use Python3.
The reason is that you have installed flask for python 3 but not for python 2.7 I assume that you might have used pip3
for installing flask if that is the case pip3
installs for python3 and pip
installs for python 2.7 by default. So check where flask has been installed if it is installed on python 3 it should be under /usr/lib/python3/dist-packages if installed on python 2.7 it should be under /usr/lib/python2.7/dist-packages . There may be additional lib paths where packages will also be searched. To see where python looks for packages
import sys
print sys.path#this will give you list of path where python searches for libraries
As "Mani" answered, you have installed flask for one of your Python environments but not the one that runs your app. To avoid this confusion, never do this:
pip install "package"
Always do this:
python -m pip install "package"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.