【问题标题】:Flask application not working烧瓶应用程序不工作
【发布时间】:2014-05-08 21:55:18
【问题描述】:

在过去的几周里,我花费了大量的时间试图让它发挥作用。 我的目标是使用 Flask 框架创建一个简单的 Web 应用程序,但我不断收到错误,并且数小时的谷歌搜索和搜索 stackoverflow 也无济于事。

我正在学习一个需要我运行的教程:$ python3 routes.py

只有我得到以下错误:

Traceback(最近一次调用最后一次): 文件“routes.py”,第 1 行,在 从烧瓶进口烧瓶,render_template ImportError:没有名为“flask”的模块

好的,没有安装 Flask?所以显然每个网站都告诉我输入 $ pip install Flask

警告:在目录“tests”下找不到匹配“”的文件 警告:在目录“docs”下找不到与“.pyc”匹配的先前包含的文件 警告:在目录“docs”下找不到与“.pyo”匹配的先前包含的文件 警告:在目录“tests”下找不到与“.pyc”匹配的先前包含的文件 警告:在目录“tests”下找不到与“.pyo”匹配的先前包含的文件 警告:在目录“examples”下找不到与“.pyc”匹配的先前包含的文件

...亚达亚达亚达...

错误:无法创建“/Library/Python/2.7/site-packages/flask”:权限被拒绝

好的,很好。我用谷歌搜索了那个错误,他们告诉我在终端中输入更多的魔法咒语。 “只需这样做,它就会起作用”......但它没有。没有任何效果。

有人愿意牵着我的手吗?我应该怎么做才能让事情正常进行?


Joshua:~ Joshua$ sudo pip install flask 下载/解压烧瓶 下载 Flask-0.10.1.tar.gz (544kB):544kB 已下载 运行 setup.py (path:/private/tmp/pip_build_root/flask/setup.py) egg_info for package flask

warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/_themes/.git'

下载/解压 Werkzeug>=0.7(来自烧瓶) 下载 Werkzeug-0.9.4.tar.gz (1.1MB):已下载 1.1MB 为 Werkzeug 包运行 setup.py (path:/private/tmp/pip_build_root/Werkzeug/setup.py) egg_info

warning: no files found matching '*' under directory 'werkzeug/debug/templates'
warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'

下载/解压 Jinja2>=2.4(来自烧瓶) 下载 Jinja2-2.7.2.tar.gz (378kB):下载了 378kB 运行 setup.py (path:/private/tmp/pip_build_root/Jinja2/setup.py) egg_info for package Jinja2

warning: no files found matching '*' under directory 'custom_fixers'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'docs'

下载/解压 itsdangerous>=0.21(来自烧瓶) 下载 itsdangerous-0.24.tar.gz (46kB):已下载 46kB 运行 setup.py (path:/private/tmp/pip_build_root/itsdangerous/setup.py) egg_info 获取包 itsdangerous

warning: no previously-included files matching '*' found under directory 'docs/_build'

下载/解压markupsafe(来自Jinja2>=2.4->flask) 下载 MarkupSafe-0.19.tar.gz 运行 setup.py (path:/private/tmp/pip_build_root/markupsafe/setup.py) egg_info 获取包markupsafe

安装收集的包:flask、Werkzeug、Jinja2、itsdangerous、markupsafe 为烧瓶运行 setup.py install

warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/_themes/.git'

为 Werkzeug 运行 setup.py 安装

warning: no files found matching '*' under directory 'werkzeug/debug/templates'
warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
no previously-included directories found matching 'docs/_build'

为 Jinja2 运行 setup.py 安装

warning: no files found matching '*' under directory 'custom_fixers'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'docs'

运行 setup.py install 会很危险

warning: no previously-included files matching '*' found under directory 'docs/_build'

为标记安全运行 setup.py install

building 'markupsafe._speedups' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c markupsafe/_speedups.c -o build/temp.macosx-10.9-intel-2.7/markupsafe/_speedups.o
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
==========================================================================
WARNING: The C extension could not be compiled, speedups are not enabled.
Failure information, if any, is above.
Retrying the build without the C extension now.


==========================================================================
WARNING: The C extension could not be compiled, speedups are not enabled.
Plain-Python installation succeeded.
==========================================================================

成功安装flask Werkzeug Jinja2 itsdangerous markupsafe 清理...

【问题讨论】:

  • 1.要在系统级别安装flask,您需要sudo,因此:sudo pip install flask(您使用的是Windows 吗?) 2. 我强烈推荐使用virtualenv。 3.除此之外,请发布具体错误。 pypi.python.org/pypi/virtualenv
  • 1.我在Mac上。 2.我尝试安装virtualenv,但没有成功。没有任何东西适用于python。我试过 sudo this 和 sudo that。我尝试过更改路径变量和各种我不理解的建议。没有任何效果。恐怕我现在所有的内部设置都搞砸了。错误已发布在 OP 和我创建的另一个线程中:stackoverflow.com/questions/22572194/… 这是一次非常令人沮丧的经历。我不明白他们为什么让这件事变得如此复杂?
  • sudo pip install setuptools && pip install python-devdocs.python-guide.org/en/latest/starting/install/osx
  • 你读过我的帖子吗?你以为我还没看过?我正在尝试让烧瓶与 python 3 一起使用。

标签: python installation flask


【解决方案1】:

好的,第一件事。 Flask 没有安装,所以我们必须先安装它。

在 UNIX(在您的情况下是 Mac)中安装东西时,您将需要 root 权限。有很多方法可以以 root 身份运行东西,最简单的是

sudo YOUR COMMAND HERE

所以如果你想安装flask,你会运行:

sudo pip install flask

然后,打开一个python shell并导入flask,它应该可以正常工作了。

 My-MacBook-Pro:~ user$ python
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>

顺便说一句,Enthought Canopy 是一个免费的 Python 环境,可以满足您的大部分 Python 需求,包括帮助您安装软件包。 如果这不起作用,请告诉我:)

【讨论】:

  • 顺便说一句,我注意到你正在使用 python3 运行你的脚本,但是将它安装在 /Library/Python/2.7/ 中,在你成功安装flask之后,尝试使用'python2.7 路由运行它.py'
  • 感谢您的回复。我尝试了 $ sudo pip install flask 但出现错误(请参阅 OP),它仍然无法正常工作。我也想用python 3。
【解决方案2】:

如果你想使用 python 3,你必须为 python 3 安装flask - 你目前只在 2.7 上安装它。

最简单的方法,如果在您的系统上配置:pip-3.0 install Flask

将 -3.0 替换为您系统上实际安装的版本。

替代方案:python3 /usr/bin/pip install Flask(pip 可能安装在其他地方?)

pip: dealing with multiple Python versions?

How to install a module use pip for specific version of?

【讨论】:

    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 2021-12-10
    相关资源
    最近更新 更多