在谷歌云平台上部署python脚本

在谷歌云平台上部署python脚本

本文介绍了在谷歌云平台上部署python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在搞清楚如何在谷歌云平台上部署我的脚本。
ive已经创建了一个包含 script.py 和 / lib 中的所有库的目录或文件夹。夹。



我没有设置我的 app.yaml 来运行 script.py (python 2.7)并访问 lib ,如果需要的话。



我也不知道是否需要使用 requirments.txt ,因为即时通讯使用第三方库。



这里是我在 script.py

中的所有输入

 导入请求
导入重新导入
导入mysql.connector $ b $ from urlparse导入urlparse $ b $ from urlparse导入urljoin
from bs4 import BeautifulSoup

另外,我在 lib 中有什么是BeautifulSoup ,请求和mysql.connector。
i不知道其他人我认为他们是python2.7内置的,因为我不能使用pip安装它们。



即时通讯使用Windows 10。

app.yaml

 运行时:python27 
api_version :1
threadsafe:true



处理程序:
- url:/ lib / requests
脚本:Scrape.app

处理程序:
- url:/请求
脚本:Scrape.app

处理程序:
- url:/ mysql / connector
脚本:Scrape.app

处理程序:
- url:/ bs4 /
脚本:Scrape.app



cron.yaml

  cron:
- description: Scrape
url:/
schedule:每10分钟
retry_parameters:
min_backoff_seconds:2.5
max_doublings:10

即时获取错误如$ / b>

 更新服务[默认] ...失败。 
错误:(gcloud.app.deploy)错误响应:[9]
应用程序启动错误:
/ bin / sh:1:Python:未找到



$ b $ pre code $ Traceback(最近一次调用最后一次)
文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py,第240行,处理
handler = _config_handle.add_wsgi_middleware(self。 _LoadHandler())
文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py,行299,位于_LoadHandler
处理程序,路径,err = LoadObject(self._handler)
在LoadObject $ b中的第85行/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py文件$ b obj = __import __(path [0])
文件/base/data/home/apps/s~tribal-bonito-157700/20170302t182530.399552845921654287/Scrape.py,第3行,放在< module> ;
导入请求
ImportError:无模块命名请求


解决方案 div>

通过表:

我建议花一些时间中的代码片段查看简单应用程序的基本结构。
$ b $ a requirements.txt 文件可用于指定列表包要安装在 lib 目录中,像这样:
$ b

pip install -r requirements.txt -t lib



但它并非绝对必要,也可以直接在 pip cmdline上直接指定包。


I'm figuring out how to deploy my script on google cloud platform.ive already made a directory or folder that contains the script.pyand all the libraries in /lib folder.

what i dont get is setting up my app.yaml to run script.py (python 2.7) and access lib if it needs to.

I also dont know if i need to make requirments.txt since im using third party libraries.

here are all my imports inside script.py

import requests
import re
import mysql.connector
from urlparse import urlparse
from urlparse import urljoin
from bs4 import BeautifulSoup

Also, what i have in my lib are BeautifulSoup,requests and mysql.connector.i dont know about the others i assume they're python2.7 built in since i cant install them using pip.

im using windows 10 by the way.

app.yaml

runtime: python27
api_version: 1
threadsafe: true



handlers:
- url: /lib/requests
  script: Scrape.app

handlers:
- url: /requests
  script: Scrape.app

handlers:
- url: /mysql/connector
  script: Scrape.app

handlers:
- url: /bs4/
  script: Scrape.app

cron.yaml

cron:
- description: "Scrape"
  url: /
  schedule: every 10 mins
  retry_parameters:
    min_backoff_seconds: 2.5
    max_doublings: 10

im getting errors like

Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
/bin/sh: 1: Python: not found


Traceback (most recent call last):
 File  "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
  File "/base/data/home/apps/s~tribal-bonito-157700/20170302t182530.399552845921654287/Scrape.py", line 3, in <module>
import requests
ImportError: No module named requests
解决方案

From the script row in the Handlers element table:

I'd recommend spending some time going through the code snippets from Quickstart for Python App Engine Standard Environment, where you'll see a basic structure of a simple app.

A requirements.txt file can be used to specify the list of packages to be installed in the lib directory, like this:

pip install -r requirements.txt -t lib

But it's not absolutely necessary, packages can be explicitly specified directly on the pip cmdline as well.

这篇关于在谷歌云平台上部署python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 23:06