Skip to content

SystemError: Parent module 'setuptools' not loaded, cannot perform relative import with setuptools 50 #2352

Closed
openreview/openreview-py
#744

Description

@gavincyi

After upgrading setuptools to 50.0 today, the environment fails to locate the entry points as it could not import distutils

$ python --version
Python 3.5.1
$ python -c "import distutils"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "/home/gchan/tmp/setuptools-python-3.5/lib/python3.5/site-packages/_distutils_hack/__init__.py", line 82, in create_module
    return importlib.import_module('._distutils', 'setuptools')
  File "/home/gchan/tmp/setuptools-python-3.5/lib64/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 981, in _gcd_import
  File "<frozen importlib._bootstrap>", line 931, in _sanity_check
SystemError: Parent module 'setuptools' not loaded, cannot perform relative import

The issue could not be found in the python 3.8 environment.

Activity

  1. aaronlee-xyz commented on Aug 31, 2020

    @aaronlee-xyz

    Found the same issue with python 3.6.1 (pyenv)

  2. akx commented on Aug 31, 2020

    @akx
    Contributor

    Same here, Ubuntu 16.04. Seems to be another symptom of #2350.

     SystemError: Parent module 'setuptools' not loaded, cannot perform relative import
       File "<frozen importlib._bootstrap>", line 931, in _sanity_check
       File "<frozen importlib._bootstrap>", line 981, in _gcd_import
         return _bootstrap._gcd_import(name[level:], package, level)
       File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
         return importlib.import_module('._distutils', 'setuptools')
       File "/usr/local/lib/python3.5/dist-packages/_distutils_hack/__init__.py", line 82, in create_module
       File "<frozen importlib._bootstrap>", line 577, in module_from_spec
       File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
       File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
       File "<frozen importlib._bootstrap>", line 969, in _find_and_load
         from distutils.version import StrictVersion
       File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 2, in <module>
         from redis.connection import (ConnectionPool, UnixDomainSocketConnection,
       File "/usr/local/lib/python3.5/dist-packages/redis/client.py", line 12, in <module>
         from redis.client import Redis, StrictRedis
       File "/usr/local/lib/python3.5/dist-packages/redis/__init__.py", line 1, in <module>
         from redis import Redis
       [...]
    
  3. ThomasDevoogdt commented on Aug 31, 2020

    @ThomasDevoogdt

    The same can be said for Matplotlib:

    main.py:6: in <module>
        import matplotlib
    ../venv/lib/python3.5/site-packages/matplotlib/__init__.py:120: in <module>
        import distutils.version
    <frozen importlib._bootstrap>:969: in _find_and_load
        ???
    <frozen importlib._bootstrap>:958: in _find_and_load_unlocked
        ???
    <frozen importlib._bootstrap>:666: in _load_unlocked
        ???
    <frozen importlib._bootstrap>:577: in module_from_spec
        ???
    ../venv/lib/python3.5/site-packages/_distutils_hack/__init__.py:82: in create_module
        return importlib.import_module('._distutils', 'setuptools')
    ../venv/lib/python3.5/importlib/__init__.py:126: in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    <frozen importlib._bootstrap>:981: in _gcd_import
        ???
    <frozen importlib._bootstrap>:931: in _sanity_check
        ???
    E   SystemError: Parent module 'setuptools' not loaded, cannot perform relative import
    
  4. NicolasPA commented on Aug 31, 2020

    @NicolasPA

    Same issue.
    Worked around with downgrading and blacklisting 50.0:

    pip install "setuptools!=50.0" --force-reinstall

    and in requirements.txt:

    setuptools!=50.0
    
  5. dwrensha commented on Aug 31, 2020

    @dwrensha

    The workaround described in the changelog worked for me:

    export SETUPTOOLS_USE_DISTUTILS=stdlib
    
  6. alepinio commented on Aug 31, 2020

    @alepinio

    Same issue here with python 3.5.2,

    ❯ pipenv
    Traceback (most recent call last):
      File "/home/apinio/.local/bin/pipenv", line 5, in <module>
        from pipenv import cli
      File "/home/apinio/.local/lib/python3.5/site-packages/pipenv/__init__.py", line 55, in <module>
        from .cli import cli
      File "/home/apinio/.local/lib/python3.5/site-packages/pipenv/cli/__init__.py", line 4, in <module>
        from .command import cli    # noqa
      File "/home/apinio/.local/lib/python3.5/site-packages/pipenv/cli/command.py", line 15, in <module>
        from .options import (
      File "/home/apinio/.local/lib/python3.5/site-packages/pipenv/cli/options.py", line 14, in <module>
        from ..utils import is_valid_url
      File "/home/apinio/.local/lib/python3.5/site-packages/pipenv/utils.py", line 16, in <module>
        from distutils.spawn import find_executable
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 577, in module_from_spec
      File "/home/apinio/.local/lib/python3.5/site-packages/_distutils_hack/__init__.py", line 82, in create_module
        return importlib.import_module('._distutils', 'setuptools')
      File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 981, in _gcd_import
      File "<frozen importlib._bootstrap>", line 931, in _sanity_check
    SystemError: Parent module 'setuptools' not loaded, cannot perform relative import
    

    Downgrading to setuptools-49.6.0 fixes the problem.

  7. 30 remaining items

  8. MartinFalatic commented on Sep 1, 2020

    @MartinFalatic

    Is this change, as implemented in 50.0.2, supposed to eliminate the need for the SETUPTOOLS_USE_DISTUTILS=stdlib workaround?

    If so, it is not working out that way. Seeing the same problem as before (without the workaround) and the build is picking up 50.0.2

    Ubuntu 18.04 with python3 (3.6.7-1~18.04) in Docker

  9. added a commit that references this issue on Sep 1, 2020
  10. cicconej commented on Sep 2, 2020

    @cicconej

    @MartinFalatic - Can you share a log/traceback? The particular exception in the original issue report was removed in Python 3.6.3 RC1+ as part of the fix for https://bugs.python.org/issue30876.

    Note the absence of https://github.com/python/cpython/blob/v3.6.2/Lib/importlib/_bootstrap.py#L920-L923 in https://github.com/python/cpython/blob/v3.6.7/Lib/importlib/_bootstrap.py#L917-L930.

  11. MartinFalatic commented on Sep 2, 2020

    @MartinFalatic

    Using setuptools 50.0.0 without workaround:

    [14:34:24][Docker Compose Build] Step 5/18 : RUN DJANGO_SECRET_KEY=redacted ENABLE_DEBUG=1 python3 manage.py collectstatic --noinput --clear
    [14:34:24][Docker Compose Build]  ---> Running in 97410cbaf12e
    [14:34:25][Docker Compose Build] Traceback (most recent call last):
    [14:34:25][Docker Compose Build]   File "manage.py", line 18, in <module>
    [14:34:25][Docker Compose Build]     execute_from_command_line(sys.argv)
    [14:34:25][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    [14:34:25][Docker Compose Build]     utility.execute()
    [14:34:25][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 357, in execute
    [14:34:25][Docker Compose Build]     django.setup()
    [14:34:25][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
    [14:34:25][Docker Compose Build]     apps.populate(settings.INSTALLED_APPS)
    [14:34:25][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 91, in populate
    [14:34:25][Docker Compose Build]     app_config = AppConfig.create(entry)
    [14:34:25][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 90, in create
    [14:34:25][Docker Compose Build]     module = import_module(entry)
    [14:34:25][Docker Compose Build]   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    [14:34:25][Docker Compose Build]     return _bootstrap._gcd_import(name[level:], package, level)
    [14:34:25][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    [14:34:25][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    [14:34:25][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
    [14:34:25][Docker Compose Build] ModuleNotFoundError: No module named 'dal'
    [14:34:25][Docker Compose Build] Service 'nginx' failed to build: The command '/bin/sh -c DJANGO_SECRET_KEY=redacted ENABLE_DEBUG=1 python3 manage.py collectstatic --noinput --clear' returned a non-zero code: 1
    

    Using setuptools 50.0.2 without workaround:

    [15:50:39][Docker Compose Build] Step 5/18 : RUN DJANGO_SECRET_KEY=redacted ENABLE_DEBUG=1 python3 manage.py collectstatic --noinput --clear
    [15:50:39][Docker Compose Build]  ---> Running in 49057705f89d
    [15:50:40][Docker Compose Build] Traceback (most recent call last):
    [15:50:40][Docker Compose Build]   File "manage.py", line 18, in <module>
    [15:50:40][Docker Compose Build]     execute_from_command_line(sys.argv)
    [15:50:40][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    [15:50:40][Docker Compose Build]     utility.execute()
    [15:50:40][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 357, in execute
    [15:50:40][Docker Compose Build]     django.setup()
    [15:50:40][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
    [15:50:40][Docker Compose Build]     apps.populate(settings.INSTALLED_APPS)
    [15:50:40][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 91, in populate
    [15:50:40][Docker Compose Build]     app_config = AppConfig.create(entry)
    [15:50:40][Docker Compose Build]   File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 90, in create
    [15:50:40][Docker Compose Build]     module = import_module(entry)
    [15:50:40][Docker Compose Build]   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    [15:50:40][Docker Compose Build]     return _bootstrap._gcd_import(name[level:], package, level)
    [15:50:40][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    [15:50:40][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    [15:50:40][Docker Compose Build]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
    [15:50:40][Docker Compose Build] ModuleNotFoundError: No module named 'dal'
    [15:50:40][Docker Compose Build] Service 'nginx' failed to build: The command '/bin/sh -c DJANGO_SECRET_KEY=redacted ENABLE_DEBUG=1 python3 manage.py collectstatic --noinput --clear' returned a non-zero code: 1
    

    Those appear to be identical.

    The following does get mentioned in the log during the main pip3 install part of the build (with and without the workaround). I mention it only for completeness as this problem is certainly affected by the setuptools version being >= 50. Note that setuptools is NOT being pinned in the requirements (as that would be problematic).

    [15:48:20][Docker Compose Build]   Found existing installation: setuptools 39.0.1
    [15:48:20][Docker Compose Build]     Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
    

    Also, 'dal' = django-autocomplete-light.

  12. MartinFalatic commented on Sep 2, 2020

    @MartinFalatic

    It's worth noting that this was closed as duplicate when I brought it up here... #2356 (comment)

    Similar but perhaps not quite the same problem after all, perhaps.

  13. added a commit that references this issue on Sep 2, 2020
  14. added a commit that references this issue on Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions