简体   繁体   English

烧瓶应用程序不起作用

[英]Flask application not working

I've spend an inordinate amount of time over the last few weeks trying to get this to work. 在过去的几周里,我花费了过多的时间来尝试使它生效。 My goal is to create a simple web app using the flask framework but I keep getting errors, and hours of googling and searching stackoverflow have not helped. 我的目标是使用flask框架创建一个简单的Web应用程序,但我一直遇到错误,并且数小时的谷歌搜索和搜索stackoverflow都没有帮助。

I'm following a tutorial that requires me to run: $ python3 routes.py 我正在遵循要求我运行的教程:$ python3 route.py

Only for me to get the following error: 只为我得到以下错误:

Traceback (most recent call last): File "routes.py", line 1, in from flask import Flask, render_template ImportError: No module named 'flask' 追溯(最近一次通话):文件“ routes.py”,行1,来自烧瓶导入烧瓶,render_template ImportError:没有名为“烧瓶”的模块

Ok so Flask is not installed? 好的,所以没有安装Flask吗? So apparently every site tells me to type $ pip install 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' 警告:未在目录“ tests”下找到与“ 相匹配的文件警告:在目录“ docs”下未找到与“ .pyc” 相匹配的先前包含的文件警告:在目录“ docs”下未找到与“ .pyo”相匹配的先前包含的文件的警告:在目录“测试”警告下未找到与“ .pyc” 相匹配的先前包含的文件:在目录“测试”警告下未找到与“ .pyo”相匹配的先前包含的文件警告:在目录下未找到与“ .pyc” 相匹配的先前包含的文件 '例子'

...yada yada yada... yada yada yada ...

error: could not create '/Library/Python/2.7/site-packages/flask': Permission denied 错误:无法创建'/Library/Python/2.7/site-packages/flask':权限被拒绝

OK great. 好,很好。 I google that error and they tell me to type more magic incantations into the terminal. 我用谷歌搜索这个错误,他们告诉我在终端中输入更多魔咒。 "Simply do this and it will work"... except it doesn't. “简单地做到这一点,它将起作用”……除非没有。 Nothing works. 什么都没有。

Is anyone willing to hold my hand through this? 有谁愿意牵着我的手吗? What should I do to get things working? 我应该怎么做才能使事情正常进行?


Joshua:~ Joshua$ sudo pip install flask Downloading/unpacking flask Downloading Flask-0.10.1.tar.gz (544kB): 544kB downloaded Running setup.py (path:/private/tmp/pip_build_root/flask/setup.py) egg_info for package flask 约书亚:〜约书亚$ sudo pip install flask下载/解压缩烧瓶下载Flask-0.10.1.tar.gz(544kB):544kB下载正在运行setup.py(路径:/private/tmp/pip_build_root/flask/setup.py)egg_info用于包装瓶

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'

Downloading/unpacking Werkzeug>=0.7 (from flask) Downloading Werkzeug-0.9.4.tar.gz (1.1MB): 1.1MB downloaded Running setup.py (path:/private/tmp/pip_build_root/Werkzeug/setup.py) egg_info for package Werkzeug 下载/解压缩Werkzeug> = 0.7(从烧瓶中)下载Werkzeug-0.9.4.tar.gz(1.1MB):下载1.1MB运行setup.py(路径:/private/tmp/pip_build_root/Werkzeug/setup.py)egg_info用于包装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'

Downloading/unpacking Jinja2>=2.4 (from flask) Downloading Jinja2-2.7.2.tar.gz (378kB): 378kB downloaded Running setup.py (path:/private/tmp/pip_build_root/Jinja2/setup.py) egg_info for package Jinja2 下载/解包Jinja2> = 2.4(从烧瓶中)下载Jinja2-2.7.2.tar.gz(378kB):378kB已下载运行的setup.py(路径:/private/tmp/pip_build_root/Jinja2/setup.py)egg_info进行打包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'

Downloading/unpacking itsdangerous>=0.21 (from flask) Downloading itsdangerous-0.24.tar.gz (46kB): 46kB downloaded Running setup.py (path:/private/tmp/pip_build_root/itsdangerous/setup.py) egg_info for package itsdangerous 下载/解压缩itsdangerous> = 0.21(从烧瓶中下载)下载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'

Downloading/unpacking markupsafe (from Jinja2>=2.4->flask) Downloading MarkupSafe-0.19.tar.gz Running setup.py (path:/private/tmp/pip_build_root/markupsafe/setup.py) egg_info for package markupsafe 下载/解压缩markupsafe(从Jinja2> = 2.4-> flask)下载MarkupSafe-0.19.tar.gz运行setup.py(路径:/private/tmp/pip_build_root/markupsafe/setup.py)egg_info用于软件包markupsafe

Installing collected packages: flask, Werkzeug, Jinja2, itsdangerous, markupsafe Running setup.py install for flask 安装收集的软件包:flask,Werkzeug,Jinja2,其危险的,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'

Running setup.py install for Werkzeug 为Werkzeug运行setup.py install

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'

Running setup.py install for Jinja2 为Jinja2运行setup.py install

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'

Running setup.py install for itsdangerous 运行setup.py install危险

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

Running setup.py install for markupsafe 运行setup.py install for markupsafe

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.
==========================================================================

Successfully installed flask Werkzeug Jinja2 itsdangerous markupsafe Cleaning up... 成功安装烧瓶Werkzeug Jinja2危险的markupsafe清理...

OK, first thing first. 好,首先 Flask is not installed so we will have to install it first. 未安装Flask,因此我们必须先安装它。

When installing stuff in UNIX (a Mac, in your case), you will need root permissions. 在UNIX(如果是Mac,则为Mac)中安装东西时,您将需要root权限。 There are many ways to run stuff as root, the easiest is 有很多方法可以以root身份运行东西,最简单的方法是

sudo YOUR COMMAND HERE

so if you want to install flask, you will run: 因此,如果要安装flask,将运行:

sudo pip install flask

then, open a python shell and import flask, it should work just fine. 然后,打开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
>>>

By the way, Enthought Canopy is a free python environment that will take care of most of your python needs, including helping you to install packages. 顺便说一句, Enthought Canopy是一个免费的python环境,它将满足您的大多数python需求,包括帮助您安装软件包。 If this doesn't work, please let me know :) 如果这不起作用,请告诉我:)

If you want to use python 3 you will have to install flask for python 3 - you are currently only installing it on 2.7. 如果要使用python 3,则必须安装python 3的flask-当前仅在2.7上安装。

Easiest way, if it is configured on your system: pip-3.0 install Flask 最简单的方法,如果在系统上进行了配置: pip-3.0 install Flask

Replace -3.0 with the version actually installed on your system. 将-3.0替换为系统上实际安装的版本。

Alternative: python3 /usr/bin/pip install Flask (pip might be installed somewhere else?) 备选: python3 /usr/bin/pip install Flask (pip可能安装在其他地方吗?)

pip: dealing with multiple Python versions? 点:处理多个Python版本?

How to install a module use pip for specific version of? 如何使用特定版本的pip安装模块?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM