如何在googleappengine上导入文本文件?

2024-04-19 11:45:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够加载我的txt文件使用下面的行在我的本地机器上。你知道吗

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

但这种方法在gcloud上是错误的。你知道吗

数据文件的屏幕截图。 enter image description here 如何在gcloud上打开这个txt文件?你知道吗

错误: TypeError:“encoding”是此函数的无效关键字参数

我正在使用谷歌应用引擎。你知道吗


Tags: 文件方法txt机器read错误openmovie
2条回答

出现此错误是因为在运行Python 3.x时,App Engine的默认运行时环境是Python 2.7。Python 2.7没有在open函数中指定编码的选项,因此关键字无效错误。你知道吗

检查this answer查看如何在python2.7上打开文件or use the Python 3 runtime。你知道吗

要使用Python 3运行时,请在app.yaml中输入以下内容:

runtime: python37

更多关于这方面的信息,您将在GCP documentation中找到。Python3.x现在可以在标准和灵活的环境中使用。关于差异,你可以阅读here。你知道吗

要运行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参数指定python版本。你知道吗

相关问题 更多 >