运行google-api-python-client的discovery.build时内核崩溃求助
discovery.build in Anaconda/Spyder (Python 3.5.4 + google-api-python-client 1.6.5) Hey there, let's tackle this kernel crash issue you're hitting with discovery.build—I’ve dealt with similar headaches using older Google client libraries and Anaconda environments, so here are some practical steps to get things working again:
1. Fix Dependency Version Conflicts
Older versions of google-api-python-client (like 1.6.5) have strict compatibility requirements with other dependencies such as httplib2 and oauth2client. Mismatched versions here are a common cause of kernel crashes.
- First, check your current dependency versions:
Open Spyder’s IPython console and run:# For Windows !pip list | findstr /i "httplib2 oauth2client" # For Linux/macOS !pip list | grep -i "httplib2 oauth2client" - Install versions known to work with your setup:
Run this in your Anaconda Prompt (after activating your environment):
These versions are tested to play nice with Python 3.5.4 and google-api-python-client 1.6.5.pip install httplib2==0.18.1 oauth2client==4.1.3
2. Ensure Spyder is Using the Correct Anaconda Environment
Sometimes Spyder’s kernel doesn’t properly link to your Anaconda environment, leading to library loading failures.
- Launch Spyder from your environment:
Open Anaconda Prompt, activate your environment with:
Then start Spyder directly with:conda activate your_environment_namespyder - Reconfigure Spyder’s interpreter:
In Spyder, go toTools > Preferences > Python interpreter, select the Python executable path from your Anaconda environment (e.g.,C:\Users\YourName\anaconda3\envs\your_env\python.exe), then restart Spyder.
3. Test with a Minimal Reproducible Code
Strip down your code to the absolute basics to isolate the issue. If this minimal code crashes, the problem is environment/dependency-related; if it works, your original code has additional conflicts.
from googleapiclient import discovery # Use a public API (like Google Books) for testing # Replace 'your_api_key' with a valid API key from Google Cloud Console service = discovery.build('books', 'v1', developerKey='your_api_key') print("Service built successfully! No kernel crash here.")
4. Check Google Cloud SDK Compatibility
Your installed Cloud SDK might clash with the older Python client library:
- Avoid relying on SDK’s default credentials for testing: Explicitly pass credentials or an API key in
discovery.build(like the example above) to bypass automatic credential loading that could trigger crashes. - If you haven’t updated the SDK recently, try a compatible update (note: Python 3.5 is end-of-life, so newer SDK versions might not support it—if updating breaks things, roll back to an older SDK version). Run in Anaconda Prompt:
gcloud components update
Start with steps 1 and 2—those resolve 90% of similar kernel crash cases with this setup. Let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者Randolfo

