Reputation: 139
I am able to load my txt file using the line below on my local machine.
lines = open('movie_lines.txt', encoding = 'utf-8', errors = 'ignore').read().split('\n')
But this method is giving error on gcloud.
ScreenShot of the data file.
how to open this txt file on gcloud?
ERROR: TypeError: 'encoding' is an invalid keyword argument for this function
I am using google App Engine for this.
Upvotes: 3
Views: 302
Reputation: 139
To run python3.x version, there is one more method which involves directly specifying in the arguments while starting the running .
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir $OUTPUT_PATH \
--runtime-version 1.12 \
--python-version 3.5 \
--module-name trainer.bot \
--package-path ./trainer \
--region $REGION \
-- \
--train-file $TRAIN_DATA
python version can be specified using python-version argument.
Upvotes: 0
Reputation: 11387
You are getting the error because the default runtime environment for App Engine is Python 2.7, while you are running Python 3.x. Python 2.7 does not have an option to specify encoding in open
function, hence invalid keyword error.
Check this answer to see how to open file on Python 2.7, or use the Python 3 runtime.
To use Python 3 runtime, put the following in your app.yaml
:
runtime: python37
More on that you will find in GCP documentation. Python 3.x is available nowadays both in standard and flexible environments. On the differences you can read here.
Upvotes: 4