Skip to content

Python 3.12 deployment fails due to outdated distlib (0.3.0) using removed modules #4418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
msetsma opened this issue May 15, 2025 · 1 comment

Comments

@msetsma
Copy link

msetsma commented May 15, 2025

Version

4.0.7030

Description

When attempting to deploy a Python function app using Python 3.12, the deployment fails because the Azure Functions Core Tools uses distlib version 0.3.0, which imports modules that were removed in Python 3.12 (imp and distutils).

The error occurs during the func pack command when creating a deployment package. The bundled distlib version tries to use these removed modules, causing the deployment to fail with errors like:

There was an error restoring dependencies. Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/tools/python/packapp/__main__.py", line 14, in <module>
    import distlib.wheel
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/tools/python/packapp/distlib/wheel.py", line 15, in <module>
    import imp
ModuleNotFoundError: No module named 'imp'

and

There was an error restoring dependencies. Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/tools/python/packapp/__main__.py", line 14, in <module>
    import distlib.wheel
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/tools/python/packapp/distlib/wheel.py", line 12, in <module>
    import distutils.util
ModuleNotFoundError: No module named 'distutils'

The issue is that both imp and distutils modules were removed in Python 3.12:

imp was deprecated since Python 3.4 and removed in 3.12
distutils was deprecated since Python 3.10 and removed in 3.12

Steps to reproduce

  1. Install Python 3.12 (I'm using 3.12.9)
  2. Install Azure Functions Core Tools v4
  3. Create a Python function app
  4. Try to deploy the function app using:
func pack --output deployment.zip

or

az functionapp deployment source config-zip --resource-group <resource-group> --name <app-name> --src <zip-file-path>
@msetsma
Copy link
Author

msetsma commented May 15, 2025

Suggested fix

The issue is in build/Settings.cs which pins distlib version 0.3.0:

public const string DistLibVersion = "distlib-0.3.0";
public const string DistLibUrl = "https://github.com/vsajip/distlib/archive/0.3.0.zip";

This needs to be updated to a newer version of distlib that's compatible with Python 3.12. The latest version (0.3.8 as of this writing) has been updated to use importlib instead of imp and has removed dependencies on distutils.

Alternatively, the bundled version could be patched to:

  1. Replace import imp with appropriate importlib imports
  2. Replace distutils.util with equivalent functionality from setuptools
  3. Replace imp.get_suffixes() with importlib.machinery.all_suffixes()

Environment

  • Azure Functions Core Tools version: 4.0.7030
  • Python version: 3.12.9
  • Operating System: macOS (Apple Silicon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant