Django 5.0.6 not installing, error: "ImportError: cannot import name 'NoneType' from 'types' (/usr/lib64/python3.9/types.py)"

SYSTEM INFORMATION
OS type and version Rocky Linux 9.4
Virtualmin version 7.10.0 Pro

When installing Django 5.0.6 to the root of a website, I am getting an error that the install failed. I was able to get past the “pip” error by searching old documents, but not this one. Full output below:

Install Script
In domain experimental.krdb.net
Found https://www.djangoproject.com:443/download/5.0.6/tarball/ in cache ..
Found https://files.pythonhosted.org:443/packages/bb/b5/26cc8f7baf0ddebd3e61a354a2bcc692cfe8005123c37ee3d8507c4c7511/flup-1.0.3.tar.gz in cache ..

Now installing Django version 5.0.6 ..
Project initialization install failed :
Traceback (most recent call last):
  File "/home/krdb/domains/experimental.krdb.net/.local/./bin/django-admin", line 33, in <module>
    sys.exit(load_entry_point('Django==5.0.6', 'console_scripts', 'django-admin')())
  File "/home/krdb/domains/experimental.krdb.net/.local/./bin/django-admin", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib64/python3.9/importlib/metadata.py", line 86, in load
    module = import_module(match.group('module'))
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/core/management/__init__.py", line 19, in <module>
    from django.core.management.base import (
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/core/management/base.py", line 14, in <module>
    from django.core import checks
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/core/checks/__init__.py", line 26, in <module>
    import django.core.checks.templates  # NOQA isort:skip
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/core/checks/templates.py", line 5, in <module>
    from django.template.backends.django import get_template_tag_modules
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/template/__init__.py", line 44, in <module>
    from .engine import Engine
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/template/engine.py", line 7, in <module>
    from .base import Template
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/template/base.py", line 60, in <module>
    from django.utils.html import conditional_escape, escape
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/utils/html.py", line 11, in <module>
    from django.utils.encoding import punycode
  File "/home/krdb/.local/lib/python3.9/site-packages/Django-5.0.6-py3.9.egg/django/utils/encoding.py", line 5, in <module>
    from types import NoneType
ImportError: cannot import name 'NoneType' from 'types' (/usr/lib64/python3.9/types.py)

Installation can be continued manually at https://experimental.krdb.net//

More information on using this script can be found at http://www.djangoproject.com/

.. installation was only partially complete.

Re-loading Webmin ..

.. done

I think this version requires your python to be 3.10 and not 3.9
https://docs.djangoproject.com/en/5.0/faq/install/#faq-python-version-support

I installed Python 3.12, and set it as the default version. Now, when I try to install Django, I get the following:

 Install Script
In domain experimental.krdb.net
Found https://www.djangoproject.com:443/download/5.0.6/tarball/ in cache ..
Found https://files.pythonhosted.org:443/packages/bb/b5/26cc8f7baf0ddebd3e61a354a2bcc692cfe8005123c37ee3d8507c4c7511/flup-1.0.3.tar.gz in cache ..

Python module setuptools is required ..
Installing package setuptools ..
Installing package(s) with command /bin/dnf -y install setuptools ..
Last metadata expiration check: 0:08:24 ago on Mon Jun 17 08:55:25 2024.
No match for argument: setuptools
Error: Unable to find a match: setuptools
.. install failed!
.. automatic Python module installation failed
Installing package python-setuptools ..
Installing package(s) with command /bin/dnf -y install python-setuptools ..
Last metadata expiration check: 0:08:27 ago on Mon Jun 17 08:55:25 2024.
Package python3-setuptools-53.0.0-12.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
.. install complete.
.. automatic Python module installation failed

So did it get installed? If not, have you tried installing the module manually?

Seems like the last hurdle…

The package “setuptools” does not exist, so it was not installed

The package “python-setuptools” is already installed, so it did not get (re)installed.

The Django install fails, and never even kicks off (unlike the previous error where it’s partial).

Installed setup tools for python-3.12 (as opposed to just Python-3), and got past that error.

Next challenge:

Now installing Django version 5.0.6 ..
Project initialization install failed :
Traceback (most recent call last):
  File "/usr/lib64/python3.12/importlib/metadata/__init__.py", line 397, in from_name
    return next(cls.discover(name=name))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/krdb/domains/experimental.krdb.net/.local/./bin/django-admin", line 33, in <module>
    sys.exit(load_entry_point('Django==5.0.6', 'console_scripts', 'django-admin')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/krdb/domains/experimental.krdb.net/.local/./bin/django-admin", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/metadata/__init__.py", line 861, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/metadata/__init__.py", line 399, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for Django
Installation can be continued manually at https://experimental.krdb.net//
More information on using this script can be found at http://www.djangoproject.com/
.. installation was only partially complete.
Re-loading Webmin ..
.. done

What version of python is officially installed on Rocky 9.4? Have you tried this with the default installation? You would think that is what the installer is based off of.

I would set it back to default and run the script. If it still blasts out errors, raise an issue with support since you have Pro version of Virtualmin.

Officially, it’s Python 3.9. I’ve made some progress getting past the various errors, but you rase a good point about the script working out of the box. If I can’t crack it manually by tonight, I’ll open the ticket.