在过去的几周里,我花了大量的时间试图让它发挥作用。 我的目标是使用flask框架创建一个简单的Web应用程序,但我不断收到错误,谷歌搜索和搜索stackoverflow的时间没有帮助。
我按照要求我运行的教程:$ python3 routes.py
只有我才能收到以下错误:
追踪(最近一次通话): 文件" routes.py",第1行,in 来自flask导入Flask,render_template ImportError:没有名为' flask'
的模块
好吧没有安装Flask?显然每个网站都告诉我输入$ pip install Flask
好的,好的。我谷歌那个错误,他们告诉我在终端输入更多魔法咒语。 "只需这样做就可以了......除了它没有。什么都行不通。警告:找不到匹配' '在目录'测试' 警告:没有以前包含的文件匹配' .pyc'在目录' docs'下找到 警告:没有以前包含的文件匹配' .pyo'在目录' docs'下找到 警告:没有以前包含的文件匹配' .pyc'在目录'测试'下找到 警告:没有以前包含的文件匹配' .pyo'在目录'测试'下找到 警告:没有以前包含的文件匹配' .pyc'在目录'示例'
下找到... yada yada yada ...
错误:无法创建' /Library/Python/2.7/site-packages/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 运行setup.py(路径:/private/tmp/pip_build_root/Werkzeug/setup.py)包装Werkzeug的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(路径:/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'
下载/拆开其危险> = 0.21(从烧瓶中) 正在下载itsdangerous-0.24.tar.gz(46kB):已下载46kB 运行setup.py(路径:/private/tmp/pip_build_root/itsdangerous/setup.py)egg_info for package itsdangerous
warning: no previously-included files matching '*' found under directory 'docs/_build'
下载/解压缩markupsafe(来自Jinja2> = 2.4->烧瓶) 正在下载MarkupSafe-0.19.tar.gz 运行setup.py(路径:/private/tmp/pip_build_root/markupsafe/setup.py)egg_info for package markupsafe
安装收集的包装:烧瓶,Werkzeug,Jinja2,itsdangerous,markupsafe 运行setup.py安装烧瓶
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 for itsdangerous
warning: no previously-included files matching '*' found under directory 'docs/_build'
为markupsafe运行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.
==========================================================================
成功安装烧瓶Werkzeug Jinja2 itsdangerous markupsafe 清理......
答案 0 :(得分:1)
好的,首先是第一件事。 Flask没有安装,因此我们必须先安装它。
在UNIX(Mac,在您的情况下)安装内容时,您将需要root权限。有很多方法可以以root身份运行东西,最简单的方法是
sudo YOUR COMMAND HERE
所以如果你想安装烧瓶,你将运行:
sudo pip install flask
然后,打开一个python shell并导入烧瓶,它应该可以正常工作。
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需求,包括帮助您安装软件包。 如果这不起作用,请告诉我:))
答案 1 :(得分:0)
如果你想使用python 3,你必须为python 3安装flask - 你目前只在2.7上安装它。
最简单的方法,如果在您的系统上配置:pip-3.0 install Flask
将-3.0替换为系统上实际安装的版本。
替代方案:python3 /usr/bin/pip install Flask
(点子可能安装在其他地方?)