简体   繁体   English

PyMongo与Python2.7

[英]PyMongo with Python2.7

I am not able to use PyMongo with Python2.7. 我无法在Python2.7中使用PyMongo。 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. 但是,当我使用Python3时,它可以成功运行。 I have a dependency on Python2.7, I can't use Python3. 我对Python2.7有依赖性,我不能使用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. 原因是您已经为python 3安装了flask,但没有为python 2.7安装,如果默认情况下pip3为python3安装而pip为python 2.7安装,则假定您可能已经使用pip3来安装flask。 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 . 因此,请检查flask的安装位置(如果安装在python 3上)应该位于/ usr / lib / python3 / dist-packages下;如果安装在python 2.7上,则应该位于/usr/lib/python2.7/dist-packages下。 There may be additional lib paths where packages will also be searched. 可能还有其他lib路径,在这些路径中还将搜索软件包。 To see where python looks for packages 查看python在哪里寻找软件包

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. 正如“ Mani”回答的那样,您已经为您的一种Python环境安装了flask,但没有为运行您的应用程序的烧瓶安装过Flask。 To avoid this confusion, never do this: 为避免这种混乱,请不要这样做:

pip install "package"

Always do this: 始终这样做:

python -m pip install "package"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM