1

I am currently trying to install the package google-api-python-client in my Azure Function (Python) I add the packages to the requirements.txt file and deploy the application to azure. But as soon as I execute the import from googleapiclient.discovery import build in my Python file there is an internal error when I trigger the function. Without the import the function returns a valid response.

Has anyone ever had that problem?

The only thing I can figure from azure log is:

Failure Exception: ContextualVersionConflict: (protobuf 3.11.3 (/azure-functions-host/workers/python/3.7/LINUX/X64), Requirement.parse('protobuf>=3.12.0'), {'google-api-core'}) Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 259, in _handle__function_load_request func_request.metadata.entry_point) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 29, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py", line 73, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 953, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "/home/site/wwwroot/HttpHeartrate/init.py", line 8, in from googleapiclient.discovery import build File "/home/site/wwwroot/.python_packages/lib/site-packages/googleapiclient/discovery.py", line 49, in import google.api_core.client_options File "/home/site/wwwroot/.python_packages/lib/site-packages/google/api_core/init.py", line 23, in version = get_distribution("google-api-core").version File "/azure-functions-host/workers/python/3.7/LINUX/X64/pkg_resources/init.py", line 482, in get_distribution dist = get_provider(dist) File "/azure-functions-host/workers/python/3.7/LINUX/X64/pkg_resources/init.py", line 358, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "/azure-functions-host/workers/python/3.7/LINUX/X64/pkg_resources/init.py", line 901, in require needed = self.resolve(parse_requirements(requirements)) File "/azure-functions-host/workers/python/3.7/LINUX/X64/pkg_resources/init.py", line 792, in resolve raise VersionConflict(dist, req).with_context(dependent_req)

1 Answer 1

1

For this problem, I can provide you with some suggestions:

1. If you added the package name to requirements.txt manually, I suggest you to use command to generate it automatically. Because there may be some error if we add it manually. You can run the command below in the "Terminal" window in your VS code.

pip freeze > requirements.txt

2. If you deploy your function from local to azure by using the VS code extension, I suggest you to use command to deploy it. Because according to my experience, deploy by extension is not reliable, sometimes it may cause some problems. So you can create the python function app in azure portal first and then run the command below in "Terminal" window to deploy it from VS code to azure.

func azure functionapp publish <functionAppName> --build remote

The <functionAppName> is the name of the function app you created on azure portal.

3. By the way, you also need to pay attention to the structure of your function app, especially the requirements.txt. If the requirements.txt in the wrong position, it will not install the packages successfully when you deploy it to azure. Below is my function app structure and I install the google-api-python-client successfully (both in local and deploy it to azure).

enter image description here

Hope it helps~

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.