4

I'm using google cloud platform for my nodejs app. Problem, after deploying the app i have access to python2.7 but not to the version 3. This one seems to be missing in the usr/bin folder.

const spawn = require("child_process").spawn;
spawn('python'); // working
spawn('/usr/bin/python3'); // not working
spawn('python3'); // not working 

Error: spawn python3 ENOENT

I used fs module to display the usr/bin folder :

...
pygettext2.7
python
python2
python2.7
pyversions
...

Any idea how can I install python3 during the deployment of the app ? Maybe changing the app.yaml file ?

Thank you

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
Julie Rankata
  • 774
  • 8
  • 12
  • Which Google App Engine environment are you using? If it's GAE Flexible, you can build a custom runtime (install Python3 or whatever you want in it) : https://cloud.google.com/appengine/docs/flexible/custom-runtimes/build. If you are using GAE Standard, then you cannot customize the runtime image (see the bullet point in https://cloud.google.com/appengine/docs/nodejs/ : *Runtime image cannot be customized*, under *Standard Environment*). – norbjd Apr 24 '19 at 12:00
  • I'm using the standard one. After a quick look it seems that the flexible method is a bit more pricy.. It's sad but i think i will just migrate my python script to the 2.7 version. – Julie Rankata Apr 24 '19 at 12:14
  • However, be aware that Python 2.7 will reach end-of-life soon (January 2020 : https://www.python.org/dev/peps/pep-0373/). OS under GAE standard nodejs environment is, by default, still configured to provide Python 2.7 instead of Python 3, for compatibility reasons probably. But this could change someday, and you have no control about your runtime on Standard Environment. Instead of using Flexible environment, or rewriting your script in a future deprecated version of Python, wouldn't it be safer to migrate from Python to nodejs instead (if possible of course)? – norbjd Apr 24 '19 at 12:32
  • Yes that was i was thinking... im also taking a look at google cloud function for execute my python script. Thank you for your help norbjd :) – Julie Rankata Apr 25 '19 at 02:44

1 Answers1

2

If you need a runtime that has both a specific version of Node.js and Python, you'd probably be better off using Cloud Run and specifying a custom image instead of trying to use one language inside another's runtime.

Flex would also possibly work here, but Cloud Run will likely be significantly cheaper, have faster startup times, and can scale to zero.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82