Quickstart for Python 3 in the App Engine Standard Environment - google-app-engine

I am following the instructions here:
https://cloud.google.com/appengine/docs/standard/python3/quickstart
At the line:
gcloud components install app-engine-python3
and getting the error:
ERROR: (gcloud.components.install) The following components are unknown [app-engine-python3]
I can't find any documentation on this error. Does anyone know the solution?

It seems to be an issue with this Quickstart, I tried to reproduce it and I got the same error.
I searched for the components by running this:
gcloud components list
And there is no app-engine-python3 component for the latest Cloud SDK version (239.0.0).
Anyway, the app-engine-python component has already Python 3. So, to use Python 3 you have to install this component:
gcloud components install app-engine-python
And then use python3 command instead of python command, e.g.:
python3 main.py

Related

Why the gcloud components update command always show restarting command

When I want to deploy my Go app to App Engine, I found that I have to install the app-engine-go. And it even said the installation is on a new window, no window popped out.
https://github.com/ChihchengHsieh/ProblemsScreenShot/blob/master/image-2.png
C:\go-work\src\orderFunc>gcloud app deploy
The component [app-engine-go] is required for staging this
application.
Restarting command:
$ gcloud components install app-engine-go
Installing component in a new window.
Please re-run this command when installation is complete.
$ gcloud app deploy
When I run the command gcloud components install app-engine-go and gcloud components update, it shows:
https://github.com/ChihchengHsieh/ProblemsScreenShot/blob/master/image.png
C:\go-work\src\orderFunc>gcloud components install app-engine-go
Restarting command:
$ gcloud components install app-engine-go
C:\go-work\src\orderFunc>gcloud components update
Restarting command:
$ gcloud components update
C:\go-work\src\orderFunc>gcloud components install app-engine-go
Restarting command:
$ gcloud components install app-engine-go
I already tried reinstalling the google cloud SDK, but it's the same.
I expect it can show some installation process.
I was trying to deploy a quickstart for .NET Google App Engine application and I run into the same issue. My issue was that I needed to execute $ gcloud components install beta to be able to deploy my GAE .NET app. And I was getting the same behavior as yours. PowerShell would print
Restarting command:
$ gcloud components install beta
but nothing actually happened. No window popup nor installation progress in the same window where I run the command. Also non of the other commands for installing or updating components were working. I could only list them with $ gcloud components list, but not install nor update any of them.
SOLUTION
I have noticed that if you run PowerShell with administrative privileges, it will open a window in C:\Windows\system32 directory. If you execute the command there, then another window will pop up and will proceed with installation or update of gcloud components. However if you cd into different directory the behavior will be as mentioned in this issue.
So to resolve this:
Run PowerShell as Administrative
If the directory is different than what I described above execute $ C:\Windows\system32 otherwise go to Step 3
Execute any command you want for gcloud components. e.g. $ gcloud components update or gcloud components install beta etc.
A window should popup and proceed with the installation or update of the components.
For me a working solution in PowerShell was this:
PS C:\Users\project> $Env:CLOUDSDK_PYTHON = gcloud components copy-bundled-python
After running this command (setting the CLOUDSDK_PYTHON envrionment varible) the command would work without opening another window:
PS C:\Users\project> gcloud components install beta
Your current Google Cloud CLI version is: 413.0.0
Installing components from version: 413.0.0
+---------------------------------------------+
| These components will be installed. |
+----------------------+------------+---------+
| Name | Version | Size |
+----------------------+------------+---------+
| gcloud Beta Commands | 2023.01.06 | < 1 MiB |
+----------------------+------------+---------+
For the latest full release notes, please visit:
https://cloud.google.com/sdk/release_notes
Do you want to continue (Y/n)?
I've also found an issue on the Google issue tracker that looks like it could be related on first glance, but it's closed as not reproducable, so if anyone knows what exactly reproduces this problem share it with Google in this issue

ImportError: cannot import name cygrpc on development Google App Engine with Firebase Cloud Firestore

I am building a RESTful API using Python 3.6, the Falcon Framework, Google App Engine, and Firebase Cloud Firestore. At runtime I am receiving the following error ...
File "E:\Bill\Documents\GitHubProjects\LetsHang-BackEnd\lib\google\cloud\firestore_v1beta1\_helpers.py", line 24, in <module> import grpc
File "E:\Bill\Documents\GitHubProjects\LetsHang-BackEnd\lib\grpc\__init__.py", line 22, in <module>
from grpc._cython import cygrpc as _cygrpc
ImportError: cannot import name cygrpc
When researching StackOverFlow, I found an article regarding an AWS Lambda deployment, but it suggests a solution based on Docker. Docker is not a viable solution for us. I also found an article off StackOverflow that suggests running "pip install grpcio". We did not without luck.
We build the App Engine dependencies using a requirements.txt file. This file has the following contents ...
falcon==1.4.1
google-api-python-client
google-cloud-firestore
firebase-admin
enum34
grpcio
We apply the requirements file using the command ...
pip install -t lib -r requirements.txt
The App Engine server is started with the command ...
dev_appserver.py .
The development environment is Windows 10.
You seem to be mixing up the GAE standard and flexible environments:
using Python 3.6 is only possible in the flexible environment (which, BTW, is fundamentally Docker-based)
installing app dependencies in the lib directory and using dev_appserver.py for local development are only applicable to the standard environment
Somehow related: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment
Ok. I will write up my findings just in case there's another fool like me.
First, Dan's response is correct. I was mixing standard and flexible environments. I had looked up a method for using the Falcon Framework with App Engine; as it turns out, the only article uses the standard environment. So that's how I wound up using dev_appserver.py. My app, however, is Python 3.6 and has dependencies that prevent stepping down to 2.7.
To develop locally for the flexible environment, you simply need to run as you normally would. In the case of Falcon Framework, that means using the Waitress wsgi server.
I find that it is a good practice to build and use a Python virtual environment. You use the virtualenv command for that. At deployment time, Google builds a docker container for the app in the cloud. To reconstruct all the necessary Python packages, you have to supply a requirements.txt file. If you have a virtual environment, then the requirements file is easily produced using pip freeze.

How to use ujson with Google App Engine

According to the official list of built-in libraries, ujson is available. However, the following app.yaml snippet:
libraries:
- name: ujson
version: '1.35'
...generates this error:
Usage: appcfg.py [options] update <directory> | [file, ...]
appcfg.py: error: Error parsing ./app.yaml: the library "ujson" is not supported
in "./app.yaml", line 89, column 1.
If I try to use other supported C libraries like numpy, it works fine. I am running SDK 159.0.0 (latest) and can even see a "ujson" entry in google-cloud-sdk/lib/googlecloudsdk/third_party/appengine/api/appinfo.py.
Any clue why ujson isn't usable?
ujson v1.35 was added to the app engine runtime in Python SDK version 1.9.55.
This sdk version wasn't included in the gcloud sdk until v161.0.0 (2017-06-28):
Updated App Engine components for Python to version 1.9.55. Please visit the release notes for details
Anecdote:
Some of us still prefer appcfg.py update . instead of gcloud app deploy app.yaml.(We are a rare and dying breed :D).
So in the past I noticed that the appcfg.py tool I was using was an older version from the older app engine tooling. Doesn't come with all the gcloud components update awesomeness. You had to download the binaries each time.
which appcfg.py should reveal the exact one being used which for me was:
$ ~/google_appengine/appcfg.py
I can't say I wasn't warned enough. Besides, I kept seeing this advice/warning each time I ran gcloud components update:
WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:
/Users/jeff/google_appengine/endpointscfg.py
/usr/local/bin/endpointscfg.py
/Users/jeff/google_appengine/dev_appserver.py
So update to the latest version, update your paths to point to the right appcfg, and enjoy ujson or any of the goodies as and when they drop.
$ ~/google-cloud-sdk/platform/google_appengine/appcfg.py update .

I can't deploy a Go module to App Engine using the google.golang.org/appengine modules

From the latest material I can read, and also based on documentation on certain APIs (for example, the Go Datastore API), I'm supposed to use google.golang.org/appengine etc. instead of the old appengine/... paths. However, when I try to deploy using gcloud preview app deploy, I get the following error:
Deployment contains files that cannot be compiled: Compile failed:
2016/01/14 14:32:43 go-app-builder: build timing: 2×6g (113ms total), 0×6l (0 total)
2016/01/14 14:32:43 go-app-builder: failed running 6g: exit status 1
server/alexa.go:10: can't find import: "golang.org/x/net/context"
The golang.org/x/net/context package supposedly replaces the old appengine/context one, but it doesn't appear to be available in the deployment server's GOROOT.
I tried including all the dependencies and their dependencies in my package repo but that only lead me to this obscure error (the directory it's complaining about actually exists):
Deployment contains files that cannot be compiled: Compile failed:
2016/01/14 14:27:04 go-app-builder: build timing: 18×6g (1.819s total), 0×6l (0 total)
2016/01/14 14:27:04 go-app-builder: failed running 6g: exit status 1
github.com/golang/protobuf/protoc-gen-go/testdata/my_test/test.pb.go:27: can't find import: "github.com/golang/protobuf/protoc-gen-go/testdata/multi"
Have I misunderstood the documentation and am only supposed to use the old packages?
You need to do a go get golang.org/x/net/context to save that package in your go src directory. Though, when working with App Engine it is not necessary. Those libraries can be imported and used, but they mostly focused on applications run outside of App Engine, i.e. Container Engine or Compute Engine. They essentially hook into the RESTful APIs Google cooked up for those services. If you decide to work directly with Google Cloud Storage you would need those libraries since App Engine expects you to use Blobstore instead. Hope this helps.
If you are using gosdk, just run goapp get in the same directory as your .go file and it will download and install the dependencies to your gosdk installation. You then deploy the app again and it should compile without problem.
When it's working there's no prompt and files will be downloaded to gosdk\gopath\src
After fininshing there will be a warning message which can be ignored:
go install: no install location for directory
C:\your_current_directory outside GOPATH
For more details see: go help gopath
For the record, this issue is now fixed with gcloud version 142.
One should now be able to deploy using gcloud beta app deploy --project <project> app.yaml. Use gcloud components update to upgrade the command line.
Here is an example project to see it work: https://github.com/aubm/my-test-app
And the Travis build logs: https://travis-ci.org/aubm/my-test-app/builds/198057096

gcloud get-logs command not working

I was trying to download logs from a GAE app using the gcloud cli
In the documentation the command I was supposed to use was:
gcloud preview app get-logs --version 1 default mylogs.txt
However, when running this command I get the following error:
ERROR: (gcloud.preview.app) Invalid choice: 'get-logs'. Did you mean 'deploy'?
All the tools are installed and there's nothing to update using gcloud components list and gcloud components update
Also I have authenticated and set the project
gcloud auth login
gcloud config set project mytestproject
This command moved to go underneath the modules command group, and unfortunately the documentation lagged behind.
The equivalent command is
$ gcloud preview app modules get-logs --version 1 default mylogs.txt
Sorry for the confusion!
You can also try appcfg.py request_logs myapp/ mylogs.txt to download the logs for your application which is running in App Engine.
This Command only works for App Engine but not for Managed VM's.Refer to the link https://cloud.google.com/appengine/docs/python/tools/uploadinganapp#Python_Downloading_logs

Resources