使用Google App Engine时无法导入Flask [英] Can't import Flask while using Google App Engine

查看:488
本文介绍了使用Google App Engine时无法导入Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循本指南并尝试开发Flask应用程序以在Google App Engine上运行。我遵循指导的信,但是当我从启动程序启动开发应用程序服务器,并转到 http:// localhost:8080 / / $>,我得到一个HTTP 500错误。

我检查日志,它说没有名为flask的模块 。然后,我通过运行 import flask 来检查管理控制台中的交互式控制台,并得到相同的错误消息。

有没有办法解决这个问题?

使用GAE和Flask工作我已经意识到这一点:



直接使用Python python app.py ),您需要在您的环境中安装依赖项包命令: pip install flask



使用dev_appserver.py运行



为了使用GAE SDK提供的dev_appserver.py运行应用程序,您需要在项目中包含所有相关的包,如下所示:Flask,jinja2 ...查看我的另一个答案示例配置这个包: https://stackoverflow.com/a/14248647/1050818



已更新



在Windows上运行Python,Virtualenv,Flask和GAE
$ b 在停止Python


  1. 安装Python http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi
  2. >
  3. 点击Windows开始按钮,然后通过编辑系统环境进行搜索并打开

  4. 转到高级选项卡并点击环境变量... / li>
  5. 添加这个; C:\\ b
  6. 当环境变量窗口打开时,从系统变量列表中选择路径, \Python27; C:\ Python27 \Scripts 在值和保存的结尾

安装setuptools MS Windows安装程序(必须在Windows上安装PIP)


  1. 在此选择正确的安装程序页面 http://pypi.python.org/pypi/setuptools#files (I使用这个: http://pypi.python。 org / packages / 2.7 / s / setuptools / setuptools-0.6c11.win32-py2.7.exe#md5 = 57e1e64f6b7c7f1d2eddfc9746bbaf20

  2. 下载安装程序并安装

安装PIP


  1. 下载PIP http://pypi.python.org/pypi/pip#downloads

  2. 解压缩到任何文件夹 >

安装Virtualenv
$ b


  1. 执行 pip install virtualenv

  2. 执行 mkdir c:\virtualenvs 创建一个虚拟Envs文件夹
  3. 执行这个 cd c:\virtualenvs 来访问该文件夹
  4. li>
  5. 执行 virtualenv flaskdemo 为您创建一个virtualenv项目

  6. 激活virtualenv c: \virtualenvs\flaskdemo\scripts\activate

安装Google App Engine SDK


  1. 安装SDK https://developers.google.com/appengine/downloads

创建项目


  1. 为您的项目创建一个目录
  2. 创建应用程序的主目录 https://github.com/maxcnunes/flaskgaedemo/blob/master/main。 py

  3. 为Google App Engine创建应用程序的配置 https:// github。 com / maxcnunes / flaskgaedemo / blob / master / app.yaml

  4. 创建一个文件让GAE初始化您的应用程序 https://github.com/maxcnunes/flaskgaedemo/blob/master/initialize_gae.py

(查看代码示例: https: //github.com/maxcnunes/flaskgaedemo



安装Flask以在本地运行


  1. 执行 pip install flask




  1. 下载Flask github.com/mitsuhiko/flask/archive/0.9.ziprel =nofollow noreferrer> https://github.com/mitsuhiko/flask/archive/0.9.zip 并在你的项目中提取文件夹瓶

  2. 下载Werkzeug https://github.com/mitsuhiko/werkzeug/archive/0.8.3.zip 并在你的项目中提取werkzeug文件夹

  3. 下载Jinja2 https://github.com /mitsuhiko/jinja2/archive/2.6.zip 并在您的项目中提取jinja2文件夹
  4. 下载简单的Json https://github.com/simplejson/simplejson/archive/v3.0.5.zip 并在你的项目中提取文件夹simplejson

使用GAE SDK运行应用程序


  1. 打开Goog​​le App Engine启动器

  2. 添加一个新应用程序
  3. 运行应用程序
  4. 点击浏览按钮,在浏览器上打开你的应用程序
  5. 最后点击Deploy按钮来部署你的appl


  6. I'm following this guide and trying to develop a Flask app to run on the Google App Engine. I followed the guide to the letter but when I launch the dev app server from the Launcher and go to http://localhost:8080/, I get a HTTP 500 error.

    I check the logs and it says No module named flask. Then I check the interactive console in the admin console by running import flask and I get the same error message. I can import flask in any other python file without error.

    Is there a way to fix this?

    解决方案

    Working a bit with GAE and Flask I have realized this:

    Running directly with Python

    To run the app with python directly (python app.py) you need have the dependents packages installed in your environment using the command: pip install flask

    Running with dev_appserver.py

    To run the app with the dev_appserver.py provided by GAE SDK you need have all dependent packages inside your project, as: Flask, jinja2... Look in my another answer a example how to configure this packages : https://stackoverflow.com/a/14248647/1050818

    UPDATED

    Running Python, Virtualenv, Flask and GAE on Windows

    Install Python

    1. Install Python http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi
    2. Click in Windows Start button and search by "Edit the system environment" and open
    3. Go to the tab Advanced and click on button "Environment Variables…"
    4. When the Environment Variables window opens, choose Path from the System variables list and click Edit…
    5. Add this ;C:\Python27;C:\Python27\Scripts at the end of the value and save

    Install setuptools MS Windows installer (Necessary to install PIP on Windows)

    1. Choose the correct installer for you in this page http://pypi.python.org/pypi/setuptools#files( I used this one: http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe#md5=57e1e64f6b7c7f1d2eddfc9746bbaf20)
    2. Download the installar and Install that

    Install PIP

    1. Download PIP http://pypi.python.org/pypi/pip#downloads
    2. Extract it to any folder
    3. From that directory, type python setup.py install

    Install Virtualenv

    1. Execute pip install virtualenv
    2. Execute this mkdir c:\virtualenvs to create a folder to the Virtual Envs
    3. Execute this cd c:\virtualenvs to access that folder
    4. Execute virtualenv flaskdemo to create a virtualenv for you project
    5. Active the virtualenv c:\virtualenvs\flaskdemo\scripts\activate

    Install Google App Engine SDK

    1. Install the SDK https://developers.google.com/appengine/downloads

    Create the project

    1. Create a directory for your project
    2. Create the main of your application https://github.com/maxcnunes/flaskgaedemo/blob/master/main.py
    3. Create the configuration of your appliction for Google App Engine https://github.com/maxcnunes/flaskgaedemo/blob/master/app.yaml
    4. Create a file to let GAE initialize your application https://github.com/maxcnunes/flaskgaedemo/blob/master/initialize_gae.py

    (Look a example of the code here: https://github.com/maxcnunes/flaskgaedemo )

    Install Flask to run Locally

    1. Execute pip install flask

    Install Flask to run on the GAE

    1. Download Flask https://github.com/mitsuhiko/flask/archive/0.9.zip and extract the folder flask inside your project
    2. Download Werkzeug https://github.com/mitsuhiko/werkzeug/archive/0.8.3.zip and extract the folder werkzeug inside your project
    3. Download Jinja2 https://github.com/mitsuhiko/jinja2/archive/2.6.zip and extract the folder jinja2 inside your project
    4. Download Simple Json https://github.com/simplejson/simplejson/archive/v3.0.5.zip and extract the folder simplejson inside your project

    Running the application with GAE SDK

    1. Open Google App Engine Launcher
    2. Add a new application
    3. Run the application
    4. Click in Browse button to open your application on browser
    5. Finally click on Deploy button to deploy your application

    这篇关于使用Google App Engine时无法导入Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆