I'm figuring out how to deploy my script on google cloud platform.
ive already made a directory or folder that contains the script.py
and 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 thelib
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.