我正在尝试从我的 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'
我注意到一些字符已附加到路径的末尾。
如何解决此问题?
请参阅 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')