How to properly import google cloud libraries in python3.6 in MACOS?

Server Fault Asked by Kid_Learning_C on November 29, 2020

I’m running a python3.6 project that uses the google cloud libraries:

from import secretmanager

def access_secret_version(project_id, secret_id, version_id=1):
    Access the payload for the given secret version if one exists. The version
    can be a version number as a string (e.g. "5") or an alias (e.g. "latest").
    # Create the Secret Manager client.
    client = secretmanager.SecretManagerServiceClient()

    # Build the resource name of the secret version.
    name = f"projects/{project_id}/secrets/{secret_id}/versions/{version_id}"

    # Access the secret version.
    response = client.access_secret_version(request={"name": name})

    # Print the secret payload.
    # WARNING: Do not print the secret in a production environment - this
    # snippet is showing how to access the secret material.
    payload ="UTF-8")
    print("Plaintext: {}".format(payload))

if __name__ == "__main__":

    access_secret_version('my-project', 'APAC_URL')
    access_secret_version('my-project', 'APAC_SECRET')
    access_secret_version('my-project', 'PASSWORD')

However, I couldn’t find a way to properly import the google cloud libraries with pip install
I haved tried venv/bin/pip install google-api-python-client and pip install -U google-cloud-secret-manager, and the console messages show that the installation was successful. However when I run the above code, I get this error:

Traceback (most recent call last):
  File "utils/", line 1, in <module>
    from import secretmanager
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/cloud/secretmanager/", line 18, in <module>
    from import (
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/cloud/secretmanager_v1/", line 18, in <module>
    from .services.secret_manager_service import SecretManagerServiceClient
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/cloud/secretmanager_v1/services/secret_manager_service/", line 18, in <module>
    from .client import SecretManagerServiceClient
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/cloud/secretmanager_v1/services/secret_manager_service/", line 27, in <module>
    from google.api_core import gapic_v1  # type: ignore
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/api_core/gapic_v1/", line 18, in <module>
    from google.api_core.gapic_v1 import config
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/google/api_core/gapic_v1/", line 23, in <module>
    import grpc
  File "/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/grpc/", line 23, in <module>
    from grpc._cython import cygrpc as _cygrpc
ImportError: dlopen(/Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/grpc/_cython/, 2): Symbol not found: __PyErr_FormatFromCause
  Referenced from: /Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/grpc/_cython/
  Expected in: flat namespace
 in /Users/my-code-base/automated_test/venv/lib/python3.6/site-packages/grpc/_cython/

I don’t know why it is so difficult to even get the libraries installed properly. It should be a very simple and smooth process. What am I missing here?

2 Answers

Answering myself here:

add the below line to requirements.txt:


Then install with pip install -r requirements.txt

Somehow this did not work at first. After some trial-and-error, it finally worked.

Answered by Kid_Learning_C on November 29, 2020

You can follow the next steps or the Official Documentation in order to set up Python Client Library:

You can also follow the next CodeLabs to set up Python Client Library for Secret Manager

Also please have a look into the Python Client for Secret Manager API

I hope it helps. Let me know if you have any issues when performing the previous steps.

Answered by Nibrass H on November 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP