无法在firebase功能中使用pandas

问题描述 投票:0回答:1

我想在我的 google cloud-firebase 功能中使用 pandas,我使用以下方法安装它:

python3 pip install pandas

并将其导入到我的函数中:

import pandas as pd

但是,在 firebase 模拟器中我遇到了这个错误:

[2023-09-26 00:04:58,056] ERROR in app: Exception on /__/functions.yaml [GET]
Traceback (most recent call last):
  File ".../venv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 122, in get_functions_yaml
    functions = get_functions()
                ^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 40, in get_functions
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File ".../main.py", line 17, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

127.0.0.1 - - [26/Sep/2023 00:04:58] "GET /__/functions.yaml HTTP/1.1" 500 -

127.0.0.1 - - [26/Sep/2023 00:04:58] "GET /__/quitquitquit HTTP/1.1" 200 -

/bin/sh: line 1: 11771 Terminated: 15          python3.11 ".../venv/lib/python3.11/site-packages/firebase_functions/private/serving.py"

import pandas as pd ModuleNotFoundError: No module named 'pandas' 

我检查了pandas是否安装正确,在jupyter笔记本中测试了这个简单的代码:

import pandas as pd
df = pd.DataFrame(
    {
            "Name": [
                "Braund, Mr. Owen Harris",
                "Allen, Mr. William Henry",
                "Bonnell, Miss. Elizabeth",
            ],
            "Age": [22, 35, 58],
            "Sex": ["male", "male", "female"],
        }
)
print(df.head(2))

看起来还不错:

enter image description here

还在“requirements.txt”的依赖中添加pandas,但错误仍然相同

# version 1, didn't work
firebase_functions~=0.1.0
pandas~=2.0.0

# version 2, also didn't work
firebase_functions~=0.1.0
pandas

我用谷歌搜索了几个小时,但找不到我丢失的内容或我应该做什么来修复它。

请有人寄给我一个救生员。

谢谢!!

python pandas firebase google-cloud-functions
1个回答
0
投票

安装步骤。

首先在终端中进入 de 文件夹

cd functions/venv/Scripts

现在输入您要安装的库

python.exe -m pip install pandas

我录制了一个视频可以帮助您,因为这是相同的过程。就我而言,效果很好。确保将它们也添加到requirement.txt中

https://www.youtube.com/watch?v=q_sayYt50oM

© www.soinside.com 2019 - 2024. All rights reserved.