小编典典

成功安装了flask,仍然出现导入错误

python

我第一次使用flask和python尝试创建Web应用程序。我在Windows
10上使用Cygwin;由于某些原因,即使我已经使用pip成功安装了flask:

$ pip install flask
Requirement already satisfied (use --upgrade to upgrade): flask in c:\python34\l                                                                                                                ib\site-packages
Requirement already satisfied (use --upgrade to upgrade): click>=2.0 in c:\pytho                                                                                                                n34\lib\site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in c:\pyth                                                                                                                on34\lib\site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in                                                                                                                 c:\python34\lib\site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in c:\py                                                                                                                thon34\lib\site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): MarkupSafe>=0.23 in c:                                                                                                                \python34\lib\site-packages (from Jinja2>=2.4->flask)
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm                                                                                                             and.

运行python app.py时仍然出现此错误:

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

有任何想法吗?对不起,如果这是一个愚蠢的问题,这是很新的。


阅读 136

收藏
2021-01-20

共1个答案

小编典典

您需要创建一个virtualenv,然后在其中安装pip。

virtualenv flasktest

下一个,

cd flasktest

然后,

source bin/activate

最后,

pip install flask

运行flask应该一切都很好(仅在virtualenv中,它无法在其外部运行。)

2021-01-20