Marison
Marison

Reputation: 139

how to import a text file on Google App Engine?

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. enter image description here 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

Answers (2)

Marison
Marison

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

Lukasz Tracewski
Lukasz Tracewski

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

Related Questions