Python找不到安装的flask包

时间:2017-09-16 02:36:40

标签: python flask pip

当我在服务器上运行flask项目时,出现以下错误:

Traceback (most recent call last):
  File "File.py", line 1, in <module>
    from flask import Flask, request
ImportError: No module named 'flask'

但我安装了烧瓶!

$sudo pip install flask
Requirement already satisfied: flask in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: click>=2.0 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: Werkzeug>=0.7 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: Jinja2>=2.4 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)

这让我发疯了。我已经尝试过其他SO答案所建议的内容,包括使用venv,但它们都会产生同样的错误。有人有建议吗?

$ which python
/usr/bin/python
$ which python3
/usr/bin/python3

我正在运行python 3.5.2

1 个答案:

答案 0 :(得分:5)

  

我正在运行python 3.5.2

正如文中所说,Flask没有安装在那里。

Requirement already satisfied: flask in /usr/local/lib/python2.7/dist-packages

如果你使用的话,这个文件夹也是系统Python,而不是virtualenv。您可以将virtualenv设置为使用系统安装的软件包,但同样,该路径不是Python3。

根本问题是使用sudo在不同的用户帐户下执行pip

使用Python2,或使用pip3python3 -m pip进行安装,您不需要sudo