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!

Related Questions

Apache reverse proxy from root to context

1  Asked on December 13, 2021 by jzonthemtn


Barman: rsync wal archival stalls on some files

1  Asked on December 13, 2021 by thoro


Unable to port forward via ssh on windows

1  Asked on December 13, 2021 by justtryingnottofail


git clone does not work in (sshfs) mapped drive in windows

0  Asked on December 13, 2021 by dhanabal-m


OpenSSL – error in SSLv2/v3 read client hello A

1  Asked on December 13, 2021 by tuyen-nguyen


Prevent port change on redirect in nginx

5  Asked on December 11, 2021 by arbales


PHP-FPM does not automatically start after reboot

3  Asked on December 11, 2021 by steveedson


Postgres roles best practice implementation

1  Asked on December 11, 2021 by jp-beaudry


Rinetd failing to run

1  Asked on December 11, 2021 by opad


Nagios service check interval based on host type

2  Asked on December 11, 2021 by sebastien-prudhomme


Cannot connect to Linux Samba share from Windows 10

15  Asked on December 11, 2021 by pngl


Ask a Question

Get help from others!

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