gcloud ml-engine local predict RuntimeError: Bad magic number in .pyc file
In fact I myself post this question to help people with the same problem, because I couldn't find an easy concise answer.
There are other solutions, in my opinion even better than mine, but this was what solved for me.
My solution was that google cloud sdk doesn't works with python 3, at least in my configuration. To solve:
- install a anaconda virtual environment with python 2 (in my case 2.7.14)
- activate the environment
- execute the gcloud command again
If your export ml model and inputs are OK that will work.
Simple problem, but caused a lot of pain to me, just because I couldn't easily find this pre-requirement or I simply missed it.
I hope help somebody.
actually it works with python3, you just need to delete the pyc files in google cloud folders, so the prediction call can compile them with python3.
to know the location of the pyc files , i did enable the flag --verbosity debug in the prediction call:
gcloud ml-engine local predict --model-dir=${MODEL_LOCATION} --json-instances=data/new-data2.json --verbosity debug
the trackback will give you info about the path of gcloud ml engine files, in my machine was:
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/command_lib/ml_engine/
go to that directory and delete the pyc files.