简体   繁体   中英

Azure Functions Python Status: 500 Internal Server Error

Exception: ModuleNotFoundError: No module named 'pandas'
Stack:   File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
    mod = importlib.import_module(fullmodname)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/site/wwwroot/HttpExample/__init__.py", line 9, in <module>
    import pandas as pd

I get this error on Azure Functions when run online. There is a requirements.txt file which contains the pandas requirement but it still manages to not find the module name pandas. Locally the function works fine.

According to the conversation in comments, I'm not sure what the problem is. But I post all of the steps I did just now for your reference, I follow the steps below and it didn't show the error message about import pandas.

  1. I create a python function in VS Code and run the command below to install pandas in local.
pip install pandas

在此处输入图像描述

Then add the code "import pandas as pd" and call the pad in the main code. 在此处输入图像描述

  1. Run the command below to generate "requirements.txt" automatically.
pip freeze > requirements.txt

在此处输入图像描述

After run this command, my "requirements.txt" show as below:

在此处输入图像描述

  1. Crate a function app(python) on azure portal with the name of "hurypyfun" and run the command below in VS code TERMINAL to deploy the function from local to azure.
func azure functionapp publish hurypyfun --build remote

在此处输入图像描述

  1. Wait a few minutes, after the deployment we can test it on azure portal. It shows success and it doesn't show the error message about import pandas. 在此处输入图像描述

Hope it would be helpful to your problem~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM