Skip to content

PubSub: ImportError after deploying Cloud Function with python3.7 and serverless #9102

Closed
@woodpav

Description

@woodpav

Environment details

I am deploying a pubsub function to python3.7 with the serverless framework using "serverless-google-cloudfunctions": "^2.3.2" and "serverless-python-requirements": "^4.3.0".

I am using google-cloud-pubsub==0.45.0 in requirements.txt

Steps to reproduce

  1. Run serverless deploy and I get the error.

My Code

I am deploying a Google Cloud function that uses the pubsub API to publish a message. However, I am getting the following error:

ImportError: cannot import name 'cygrpc' from 'grpc._cython'

It seems to be because you can't pip install a C library with requirements.txt. How to I fix this? My code is below.

from google.cloud import pubsub

publisher = pubsub.PublisherClient()
path = publisher.topic_path("my_proj", "my_topic")

publisher.publish(path, "test".encode("utf-8"))

My requirements.txt is the following. I have tried adding grpcio==1.22.0 to no avail.

google-cloud-pubsub==0.45.0

My serverless.yml:

service: my-service

provider:
    name: google
    stage: ${opt:stage, 'dev'}
    runtime: python37
    region: us-central1
    project: ${self:custom.env.PROJECT_NAME}
    credentials: ~/.gcloud/keyfile.json

plugins:
  - serverless-google-cloudfunctions
  - serverless-python-requirements

custom:
    pythonRequirements:
        fileName: private_requirements.txt
        pythonBin: python3
        noDeploy:
            - requirements.txt
    stage:
        ${self:provider.stage}
    env:
        ${file(./.env.${self:provider.stage})}

package:
    include:
        - requirements.txt
    exclude:
        - .git/**
        - .gitignore
        - env*
        - node_modules/**
        - package.json
        - private_requirements.txt
        - yarn.lock

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.externalThis issue is blocked on a bug with the actual product.packagingtype: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions