python - flask 应用程序不工作

标签 python installation flask

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

我正在遵循一个需要我运行的教程:$ python3 paths.py

只有我收到以下错误:

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

好的,那么 Flask 还没有安装吗?所以显然每个网站都告诉我输入 $ pip install 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'

...yada yada yada...

error: could not create '/Library/Python/2.7/site-packages/flask': Permission denied

好的,太好了。我用谷歌搜索了这个错误,他们告诉我在终端中输入更多的魔法咒语。 “只要这样做,它就会起作用”……但事实并非如此。没有任何效果。

有人愿意牵着我的手度过这一切吗?我应该做什么才能让事情正常运转?

<小时/>

约书亚:〜约书亚$ sudo pip install Flask 下载/解压 flask 下载 Flask-0.10.1.tar.gz (544kB):已下载 544kB 运行setup.py(路径:/private/tmp/pip_build_root/flask/setup.py)egg_info包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(来自 flask ) 下载 Werkzeug-0.9.4.tar.gz (1.1MB):已下载 1.1MB 运行setup.py(路径:/private/tmp/pip_build_root/Werkzeug/setup.py)egg_info for package Werkzeug

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(来自 Flask) 下载 Jinja2-2.7.2.tar.gz (378kB):已下载 378kB 运行Jinja2包的setup.py(路径:/private/tmp/pip_build_root/Jinja2/setup.py)egg_info

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'

下载/解压其危险>=0.21(来自 flask ) 下载itsdangerous-0.24.tar.gz (46kB):已下载46kB 运行setup.py(路径:/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(路径:/private/tmp/pip_build_root/markupsafe/setup.py)egg_info来获取包markupsafe

安装收集的软件包:flask、Werkzeug、Jinja2、itsdangerous、markupsafe 为 Flask 运行 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 其危险标记安全 清理...

最佳答案

好的,首先是第一件事。 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 需求,包括帮助您安装软件包。 如果这不起作用,请告诉我:)

关于python - flask 应用程序不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22729747/

相关文章:

python - 从 0/1 网格返回值

python - 如何使用 BS4 迭代 <td> 标签?

wix - 为什么 MSI 安装程序在更新时要求重新启动?

python - OpenCV VideoCapture 在 Flask 项目中不起作用,但在基本示例中起作用

flask - 在代码或 `flask run` 命令中指定 Flask 重新加载监视列表(extra_files)

postgresql - 炼金术;计算一段时间内两个日期之间的项目

python - 计算双阶乘时出现问题 : computer or code?

python - simplekml 中的 html 弹出窗口

linux - 如何在没有 X 的 Linux 上安装 Oracle 11g?

compiler-errors - 在Debian 8.6上安装CouchDB 2.0.0失败