使用 Python 灵活环境在 virtualenv 中包含 Google Cloud SDK
Including Google Cloud SDK in virtualenv using Python Flexible Environment
我想使用 google.appengine.api 图像包,但我不知道如何安装 virtualenv 的工具。当我在我的正常环境中使用 dev_appserver.py 时,该包工作正常,但是当我使用带有 flask 的灵活环境时,它找不到该包。有没有办法将图像库添加到我的 virtualenv 中?
当我在将图像上传到服务器之前尝试使用 Pillow 调整图像大小时,但当我这样做时,图像将以 0B 的速度到达云存储。
if file and allowed_file(file.filename):
filename = '%s_%s.jpg' % (item.id, len(item.photos))
# Resize file using pillow
image = Image.open(file)
image.thumbnail((300,300)
resized_image = io.BytesIO()
image.save(resized_image, format='JPEG')
# if I did a image.show() here the image would
# properly be shown resized
gcs = storage.Client()
bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)
blob = bucket.blob(filename)
blob.upload_from_file(resized_image,
content_type=file.content_type)
# I would then view the image in the bucket and it shows up as 0 bytes
# and blank
# If I just use the regular file it uploads fine.
您可能不走运,图像服务在标准环境之外不可用。
来自Migrating Services from the Standard Environment to the Flexible Environment:
The Images service is not available outside of the standard
environment. However, you can easily serve images directly from your
application or directly from Cloud Storage.
If you need to do image processing, you can install and use any image
processing library such as Pillow.
The Images service also provided functionality to avoid dynamic
requests to your application by handling image resizing using a
serving URL. If you want similar functionality, you can generate the
re-sized images ahead of time and upload them to Cloud Storage for
serving. Alternatively, you could use a third-party content delivery
network (CDN) service that offers image resizing.
For more resources, see the following guides:
我想使用 google.appengine.api 图像包,但我不知道如何安装 virtualenv 的工具。当我在我的正常环境中使用 dev_appserver.py 时,该包工作正常,但是当我使用带有 flask 的灵活环境时,它找不到该包。有没有办法将图像库添加到我的 virtualenv 中?
当我在将图像上传到服务器之前尝试使用 Pillow 调整图像大小时,但当我这样做时,图像将以 0B 的速度到达云存储。
if file and allowed_file(file.filename):
filename = '%s_%s.jpg' % (item.id, len(item.photos))
# Resize file using pillow
image = Image.open(file)
image.thumbnail((300,300)
resized_image = io.BytesIO()
image.save(resized_image, format='JPEG')
# if I did a image.show() here the image would
# properly be shown resized
gcs = storage.Client()
bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)
blob = bucket.blob(filename)
blob.upload_from_file(resized_image,
content_type=file.content_type)
# I would then view the image in the bucket and it shows up as 0 bytes
# and blank
# If I just use the regular file it uploads fine.
您可能不走运,图像服务在标准环境之外不可用。
来自Migrating Services from the Standard Environment to the Flexible Environment:
The Images service is not available outside of the standard environment. However, you can easily serve images directly from your application or directly from Cloud Storage.
If you need to do image processing, you can install and use any image processing library such as Pillow.
The Images service also provided functionality to avoid dynamic requests to your application by handling image resizing using a serving URL. If you want similar functionality, you can generate the re-sized images ahead of time and upload them to Cloud Storage for serving. Alternatively, you could use a third-party content delivery network (CDN) service that offers image resizing.
For more resources, see the following guides: