使用Python灵活的环境在VirtualEnvironment中包含Google Cloud SDK

使用Python灵活的环境在VirtualEnvironment中包含Google Cloud SDK,python,google-app-engine,google-cloud-platform,virtualenv,pillow,Python,Google App Engine,Google Cloud Platform,Virtualenv,Pillow,我想使用google.appengine.api图像包,但我不知道如何安装virtualenv的工具。当我在我的普通环境中使用dev_appserver.py时,该包可以正常工作,但当我在flask中使用flexible环境时,它找不到该包。有没有办法将图像库添加到我的virtualenv中 当我在上传到服务器之前尝试使用Pillow调整图像大小时,但当我这样做时,图像将以0B的速度到达云存储 if file and allowed_file(file.filename): filena

我想使用google.appengine.api图像包,但我不知道如何安装virtualenv的工具。当我在我的普通环境中使用dev_appserver.py时,该包可以正常工作,但当我在flask中使用flexible环境时,它找不到该包。有没有办法将图像库添加到我的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.

您可能运气不好,图像服务在标准环境之外不可用

从:

图像服务在标准之外不可用 环境但是,您可以轻松地直接从您的 应用程序或直接从云存储

如果需要进行图像处理,可以安装和使用任何图像 处理库,例如

图像服务还提供了避免动态变化的功能 通过使用 服务URL。如果需要类似的功能,可以生成 提前重新调整图像大小,并将其上载到云存储以备将来使用 服务或者,您可以使用第三方内容交付 提供图像大小调整的网络(CDN)服务

有关更多资源,请参阅以下指南:


谢谢你的回答。你完全回答了我。我已经编辑了这个问题,并说明了当我使用枕头时会发生什么。你能帮我回答这部分问题吗?你能检查一下
resized\u image
是否包含你期望的内容吗?也许
blob.upload\u from\u file(resized\u image.get\u value(),…
?请参阅尝试使用真实文件而不是
io.BytesIO
。如果这样做有效,则显然是
io.BytesIO
匹配问题,这是我怀疑的。我无法测试自己,因为我既没有使用flex env也没有使用flask…如果使用
f
的句柄调用
blob.upload\u from\u file()