将BigQuery查询结果转换为DataFrame时出现PyArrow导入错误
to_dataframe() Here are actionable fixes to resolve the PyArrow import error you're encountering:
Verify PyArrow version compatibility
Thegoogle-cloud-bigquerylibrary has strict version requirements for PyArrow. Runpip show google-cloud-bigqueryand check theRequires-Distfield to see the supported PyArrow version range. Install the correct version with:pip install pyarrow==<compatible_version>Alternatively, install the
google-cloud-bigquerypackage with its pyarrow extra to automatically get a compatible version:pip install google-cloud-bigquery[pyarrow]Confirm your Python environment
Ensure you're working in the correct virtual environment where PyArrow is installed. Runpip listto check if PyArrow appears in the package list. If not, activate the right environment and reinstall the packages there.Reinstall corrupted packages
Corrupted installations can cause import issues. Uninstall and reinstall the relevant packages:pip uninstall -y google-cloud-bigquery pyarrow pip install google-cloud-bigquery pyarrowCheck for conflicting local files
Make sure there are no files namedpyarrow.pyor directories namedpyarrowin your project root. These will shadow the official PyArrow library and prevent proper imports.Alternative: Use pandas-gbq directly
If the above fixes don't work, bypass theto_dataframe()method by usingpandas-gbqto fetch the query results directly into a DataFrame:import pandas as pd from google.oauth2 import service_account credentials_path = "credential path" credentials = service_account.Credentials.from_service_account_file(credentials_path) project_id = "project id" df = pd.read_gbq( "SELECT * FROM table", project_id=project_id, credentials=credentials )
内容的提问来源于stack exchange,提问作者Chris

