【发布时间】:2023-12-16 09:19:01
【问题描述】:
我正在 mi gcloud 存储桶中设置一个新功能,允许我使用名为“boto”的 python 库上传或下载文件,但出现此错误
我正在使用最新版本的 linux、visual studio code、python 3.7、gsutil 和 boto。
import os
import boto
import gcs_oauth2_boto_plugin
import shutil
import io
import tempfile
import time
import sys
# Activate virtual environment
activate_this = os.path.join(VENV + 'bin/activate_this.py')
exec(open(activate_this, dict(__file__=activate_this)))
# Check arguments
if len(sys.argv) < 2:
print ("Usage: " + sys.argv[0] + ' FILENAME')
quit()
filename = sys.argv[1]
# URI scheme for Cloud Storage.
GOOGLE_STORAGE = "gs"
# URI scheme for accessing local files.
LOCAL_FILE = "file"
header_values = {"x-goog-project-id": PROJECT_ID}
# Open local file
with open(filename, 'r') as localfile:
dst_uri = boto.storage_uri(BUCKET + '/' + filename, GOOGLE_STORAGE)
# The key-related functions are a consequence of boto's
# interoperability with Amazon S3 (which employs the
# concept of a key mapping to localfile).
dst_uri.new_key().set_contents_from_file(localfile)
print ('Successfully created "%s/%s"' % (dst_uri.bucket_name, dst_uri.object_name))
Traceback(最近一次调用最后一次): 文件“./upload2gcs.py”,第 10 行,在 进口博托 ImportError: 没有名为 boto 的模块
【问题讨论】:
-
我假设这个文件是“upload2gcs.py”,但第 10 行没有任何内容。这是您的“import boto”语句在真实文件中的位置吗?
-
尝试“import .boto”
标签: python-3.x boto gcloud