Kanji
Kanji

Reputation: 1

No module named '_cffi_backend' with gspread module

I tried to import gspread. I could successfully import until last week, but it fails from this Monday.

import sys
sys.path.append("/usr/local/lib/python3.10/site-packages")
import gspread

It returns an error, ModuleNotFoundError: No module named '_cffi_backend', although I have already installed cffi:

ModuleNotFoundError: No module named '_cffi_backend'
thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.20.2/src/err/mod.rs:788:5:
Python API call failed
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/hamident0/test/test.py", line 4, in <module>
    import gspread
  File "/usr/local/lib/python3.10/site-packages/gspread/__init__.py", line 7, in <module>
    from .auth import (
  File "/usr/local/lib/python3.10/site-packages/gspread/auth.py", line 15, in <module>
    from google.oauth2.credentials import Credentials as OAuthCredentials
  File "/usr/local/lib/python3.10/site-packages/google/oauth2/credentials.py", line 44, in <module>
    from google.oauth2 import reauth
  File "/usr/local/lib/python3.10/site-packages/google/oauth2/reauth.py", line 40, in <module>
    from google.oauth2 import _client
  File "/usr/local/lib/python3.10/site-packages/google/oauth2/_client.py", line 35, in <module>
    from google.auth import jwt
  File "/usr/local/lib/python3.10/site-packages/google/auth/jwt.py", line 57, in <module>
    from google.auth import _service_account_info
  File "/usr/local/lib/python3.10/site-packages/google/auth/_service_account_info.py", line 22, in <module>
    from google.auth import crypt
  File "/usr/local/lib/python3.10/site-packages/google/auth/crypt/__init__.py", line 43, in <module>
    from google.auth.crypt import rsa
  File "/usr/local/lib/python3.10/site-packages/google/auth/crypt/rsa.py", line 20, in <module>
    from google.auth.crypt import _cryptography_rsa
  File "/usr/local/lib/python3.10/site-packages/google/auth/crypt/_cryptography_rsa.py", line 22, in <module>
    import cryptography.exceptions
  File "/usr/local/lib/python3.10/site-packages/cryptography/exceptions.py", line 9, in <module>
    from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
pyo3_runtime.PanicException: Python API call failed

I deleted and reinstalled related packages (gspread, cffi). I confirmed that cffi is at /usr/local/lib/python3.10/site-packages with pip3 show cffi.

How can I successfully import gspread?

Upvotes: 0

Views: 506

Answers (1)

Anas Knefati
Anas Knefati

Reputation: 21

I had the same problem and I fixed it by reinstalling the cffi package:

pip install --upgrade --force-reinstall cffi

Upvotes: 0

Related Questions