You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.7调用BigQuery时出现ModuleNotFoundError: No module named 'google'错误的求助

Fixing ModuleNotFoundError: No module named 'google' for Python 3.7 + BigQuery

Hey there, let's work through this frustrating error step by step—this is super common when dealing with Python environments on macOS, so you're not alone! Here are the most likely fixes to get your BigQuery code running:

1. Make sure you're installing the library for the right Python version

macOS comes with Python 2 pre-installed, which often causes confusion. If you ran just pip install google-cloud-bigquery, it might have installed the library for Python 2 instead of your 3.7 version.

  • First, confirm your Python 3.7 path:

    python3.7 --version
    

    You should see something like Python 3.7.x printed.

  • Then install the library specifically for Python 3.7 using its corresponding pip:

    pip3.7 install google-cloud-bigquery
    

Virtual environments keep your project dependencies isolated, so you don't run into version conflicts or "wrong environment" issues. Here's how to set one up for your BigQuery project:

  • Create a virtual environment (name it whatever you want, like bigquery-env):

    python3.7 -m venv bigquery-env
    
  • Activate the environment (you'll see (bigquery-env) at the start of your terminal prompt when it's active):

    source bigquery-env/bin/activate
    
  • Now install the BigQuery library inside this environment:

    pip install google-cloud-bigquery
    
  • When you're done working, you can deactivate the environment with:

    deactivate
    

3. Verify your Python interpreter in your code editor

If you're using an IDE like VS Code or PyCharm, it might be using a different Python interpreter than the one you installed the library for.

  • For VS Code: Press Cmd+Shift+P, search for "Python: Select Interpreter", and pick the Python 3.7 version (or the virtual environment you created, which will show up as ./bigquery-env/bin/python).

  • For PyCharm: Go to File > Settings > Project: [your project name] > Python Interpreter, and select the correct Python 3.7 interpreter or virtual environment.

4. Double-check your PATH and installed packages

If the above steps don't work, let's confirm where the library is installed and that your Python can find it:

  • List all packages installed for Python 3.7:

    pip3.7 list
    

    Look for google-cloud-bigquery in the output—if it's not there, re-run the install command from step 1.

  • Check which Python your terminal is using by default:

    which python
    

    If this points to /usr/bin/python (the system Python 2), you'll need to use python3.7 explicitly to run your script:

    python3.7 your_script_name.py
    

5. Reinstall the library (clean slate)

If there was a corrupted install, try uninstalling and reinstalling:

pip3.7 uninstall google-cloud-bigquery
pip3.7 install --upgrade google-cloud-bigquery

Once you've done one of these steps, test the import in your terminal first to confirm:

python3.7
>>> from google.cloud import bigquery
>>> # No error? Great! Now run your sample code.

内容的提问来源于stack exchange,提问作者Jad Edlebi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 02:57:44