ModuleNotFoundError: No module named 'google.cloud' When deploying Streamlit App to Heroku

ModuleNotFoundError: No module named 'google.cloud' When deploying Streamlit App to Heroku

我在本地创建了一个 python streamlit 应用程序,我的代码中有以下导入;

import requests
import geopandas as gpd
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go
import plotly
import matplotlib.pyplot as plt
import streamlit as st
from google.cloud import bigquery
from google.oauth2 import service_account

之后我命令了一个 requirements.txt 文件,它创建了以下 ;

pandas==1.3.2
numpy==1.21.2
plotly==5.2.1
geopandas==0.9.0
requests==2.26.0
streamlit==0.86.0
matplotlib==3.4.3
protobuf==3.17.3

在本地,效果很好。 我已成功将我的应用程序部署到 heroku,但是当我 运行 该应用程序时它显示 ;

ModuleNotFoundError: 没有名为 'google.cloud'

的模块

我在我的代码中使用 bigquery 查询并使用 service_account 获取查询结果。

要访问 bigquery,您需要将该库添加到您的 requirements.txt 文件中:

pip install google-cloud-bigquery

我通过在 requirements.txt 中添加以下内容解决了我的问题;

google.cloud < 0.34.0
google.cloud.bigquery < 2.24.0
google.cloud.core < 1.7.2
google.auth < 1.34.0
google.resumable.media < 1.3.3
google.api.core < 1.31.1

google-cloud-bigquery本身还不够,还依赖于以下几点;

google-cloud-core  
google-auth  
google.resumable.media  
google.api.core