本地运行App Engine导入BigQuery库报DistributionNotFound错误求助
The error you're encountering happens because the local App Engine development server runs in an isolated environment and doesn't automatically recognize globally installed Python packages. Even though you installed google-cloud-bigquery via pip, the App Engine SDK's setuptools can't locate it. Here's how to resolve this:
Step 1: Install the package into your project's local lib directory
Instead of installing globally, install the package directly into a lib folder within your project. This ensures App Engine can access it. Since you're using Python 2.7 (evident from the traceback), use pip2.7 to target the correct Python version:
pip2.7 install --upgrade google-cloud-bigquery==1.28.0 -t lib
Note: Version 1.28.0 is the last release of google-cloud-bigquery that supports Python 2.7. Newer versions drop Python 2.7 compatibility, so specifying this version is critical.
Step 2: Configure App Engine to use the local lib folder
Create an appengine_config.py file in the root directory of your project (same level as app.yaml). Add the following code to tell App Engine to load libraries from the lib folder:
from google.appengine.ext import vendor # Add libraries installed in the "lib" folder to the Python path vendor.add('lib')
Step 3: Verify the setup
Ensure the lib folder exists in your project and contains the google directory (along with other dependencies). Restart your local App Engine dev server, and the import should work correctly.
Additional Checks
- If you're using a virtual environment, activate it before running the pip command to ensure you're installing into the right context.
- Double-check that your project's
app.yamldoesn't exclude thelibfolder (it should be included by default unless you've added it to a skip list).
内容的提问来源于stack exchange,提问作者Manuel Godoy

