本文介绍了成功安装了flask,仍然出现导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working with flask and python for the first time trying to create a web app. I'm on Windows 10 using Cygwin; for some reason, even though I've successfully installed flask using pip:

$ 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时仍然出现此错误:

I still get this error when running 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

有什么想法吗?抱歉,这是一个愚蠢的问题,这是个很新的问题.

any ideas? Sorry if this is a dumb question, pretty new at this.

推荐答案

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

You need to create a virtualenv and then install pip in that.

virtualenv flasktest

下一步

cd flasktest

然后

source bin/activate

最后

pip install flask

运行flask会让您一切都好(仅在virtualenv中,它将无法在其外部运行.)

You should be all good with running flask (only in the virtualenv, it will not work outside of it.)

这篇关于成功安装了flask,仍然出现导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:12