AWS:FileNotFoundError:[Errno 2]没有这样的文件或目录

时间:2019-07-10 11:34:22

标签: amazon-web-services amazon-s3 jupyter-notebook amazon-sagemaker

我正在尝试从S3存储桶中将文件下载到sagemaker。

文件的路径是 s3://vemyone/input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm

该文件的路径作为列表元素存储在train_fns[0]

train_fns[0]的值为

input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm

我使用了以下代码:

s3 = boto3.resource('s3')
bucketname = 'vemyone'

s3.Bucket(bucketname).download_file(train_fns[0][:], train_fns[0])

但出现以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm.5b003ba1'

我注意到某些字符已经附加在路径的末尾。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

请参阅https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.download_file

根据文档,第一个参数是文件密钥,第二个参数是本地文件的路径:

s3 = boto3.resource('s3')
bucketname = 'vemyone'

s3.Bucket(bucketname).download_file(train_fns[0], '/path/to/local/file')