简体   繁体   English

如何在Google App Engine上导入文本文件?

[英]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. 我可以使用本地计算机上面的行加载我的txt文件。

lines = open('movie_lines.txt', encoding = 'utf-8', errors = 'ignore').read().split('\n')

But this method is giving error on gcloud. 但是这种方法在gcloud上给出了错误。

ScreenShot of the data file. ScreenShot的数据文件。 在此输入图像描述 how to open this txt file on gcloud? 如何在gcloud上打开此txt文件?

ERROR: TypeError: 'encoding' is an invalid keyword argument for this function 错误: TypeError:'encoding'是此函数的无效关键字参数

I am using google App Engine for this. 我正在使用谷歌App Engine。

You are getting the error because the default runtime environment for App Engine is Python 2.7, while you are running Python 3.x. 您收到错误是因为App Engine的默认运行时环境是Python 2.7,而您运行的是Python 3.x. Python 2.7 does not have an option to specify encoding in open function, hence invalid keyword error. Python 2.7没有在open函数中指定编码的选项,因此无效的关键字错误。

Check this answer to see how to open file on Python 2.7, or use the Python 3 runtime . 查看此答案以了解如何在Python 2.7上打开文件, 或使用Python 3运行时

To use Python 3 runtime, put the following in your app.yaml : 要使用Python 3运行时,请在app.yaml以下内容:

runtime: python37

More on that you will find in GCP documentation . 有关详细信息,请参阅GCP文档 Python 3.x is available nowadays both in standard and flexible environments. Python 3.x现在在标准和灵活环境中都可用。 On the differences you can read here . 关于差异,你可以在这里阅读。

To run python3.x version, there is one more method which involves directly specifying in the arguments while starting the running . 要运行python3.x版本,还有一个方法涉及在开始运行时直接指定参数。

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 . 可以使用python-version参数指定python版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM