Skip to content
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

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

Closed
gavincyi opened this issue Aug 31, 2020 · 23 comments · Fixed by openreview/openreview-py#744 or #2369

Comments

@gavincyi
Copy link

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.

@aaronlee-xyz
Copy link

aaronlee-xyz commented Aug 31, 2020

Found the same issue with python 3.6.1 (pyenv)

@akx
Copy link
Contributor

akx commented Aug 31, 2020

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
   [...]

@ThomasDevoogdt
Copy link

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

@NicolasPA
Copy link

Same issue.
Worked around with downgrading and blacklisting 50.0:

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

and in requirements.txt:

setuptools!=50.0

chigby added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Aug 31, 2020
Experiencing a problem where `pip install pipenv` yields:

```
SystemError: Parent module 'setuptools' not loaded, cannot perform
relative import
```

Fix inspired by:

pypa/setuptools#2352
chigby added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Aug 31, 2020
Experiencing a problem where `pip install pipenv` yields:

```
SystemError: Parent module 'setuptools' not loaded, cannot perform
relative import
```

Fix inspired by:

pypa/setuptools#2352
chigby added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Aug 31, 2020
Experiencing a problem where `pip install pipenv` yields:

```
SystemError: Parent module 'setuptools' not loaded, cannot perform
relative import
```

Fix inspired by:

pypa/setuptools#2352
chigby added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Aug 31, 2020
Experiencing a problem where `pip install pipenv` yields:

```
SystemError: Parent module 'setuptools' not loaded, cannot perform
relative import
```

Fix inspired by:

pypa/setuptools#2352
chigby added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Aug 31, 2020
Experiencing a problem where `pip install pipenv` yields:

```
SystemError: Parent module 'setuptools' not loaded, cannot perform
relative import
```

Fix inspired by:

pypa/setuptools#2352
tfds-copybara pushed a commit to tensorflow/datasets that referenced this issue Aug 31, 2020
tfds-copybara pushed a commit to tensorflow/datasets that referenced this issue Aug 31, 2020
@dwrensha
Copy link

The workaround described in the changelog worked for me:

export SETUPTOOLS_USE_DISTUTILS=stdlib

@alepinio
Copy link

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.

tfds-copybara pushed a commit to tensorflow/datasets that referenced this issue Aug 31, 2020
openstack-mirroring pushed a commit to openstack/project-config that referenced this issue Aug 31, 2020
setuptools==50 doesn't work with python older than python3.8. There are
a number of issues [0][1][2] the first of which we are tripping over. Be
conservative here and install older setuptools until these issues on
python3.5, 3.6, and 3.7 are sorted out.

[0] pypa/setuptools#2352
[1] https://github.com/pypa/setuptools/issues/2363
[2] pypa/setuptools#2357

Change-Id: I1ae7251c8a4c214544524871fdfe51e947b638f8
leezu added a commit to leezu/mxnet that referenced this issue Aug 31, 2020
bors bot added a commit to eol-uchile/edx-staging that referenced this issue Sep 1, 2020
196: Blacklist setuptools 50.0 while the build is not fixed r=fdns a=fdns

pypa/setuptools#2352

bors r+

Co-authored-by: Felipe Espinoza <fdns@users.noreply.github.com>
@jaraco
Copy link
Member

jaraco commented Sep 1, 2020

Good insight. Sounds like a good mitigation.

jaraco added a commit that referenced this issue Sep 1, 2020
pshanbhag added a commit to platform9/express-cli that referenced this issue Sep 1, 2020
New version of setuptools breaks our install model. This change uses one of the
suggested workarounds for it. Upstream issue:
pypa/setuptools#2352
pshanbhag added a commit to platform9/express-cli that referenced this issue Sep 1, 2020
New version of setuptools breaks our install model. This change uses one of the
suggested workarounds for it. Upstream issue:
pypa/setuptools#2352
@MartinFalatic
Copy link

MartinFalatic commented Sep 1, 2020

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

tfx-copybara pushed a commit to tensorflow/tfx-bsl that referenced this issue Sep 1, 2020
We are using python 3.6.1 which suffers from pypa/setuptools#2352 even with setuptools 50.0.1 (which should fix the "bug" for newer py36)

PiperOrigin-RevId: 329607958
@cicconej
Copy link

cicconej commented Sep 2, 2020

@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.

@MartinFalatic
Copy link

MartinFalatic commented Sep 2, 2020

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.

@MartinFalatic
Copy link

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.

tfds-copybara pushed a commit to tensorflow/datasets that referenced this issue Sep 2, 2020
wmfgerrit pushed a commit to wikimedia/labs-tools-heritage that referenced this issue Sep 2, 2020
By default the image comes with setuptools==33.1.1. But pywikibot
requires that setuptools>=40.1.0 be installed BEFORE pip tries to
install it. Pin it to 49.3.0 since 50.0.0 seems to be broken for python 3.5
pypa/setuptools#2352.

Added the `pip --version` command since the `pip install --upgrade pip`
command otherwise seems to have no effect.

Change-Id: I1583ae92084dd84f12359a8f3fcfdfb72214f1af
szha pushed a commit to apache/mxnet that referenced this issue Sep 2, 2020
* fix cu102 link on pypi

* fix setuptool import issue pypa/setuptools#2352
gvanrossum added a commit to python/mypy that referenced this issue Sep 2, 2020
jsugarman added a commit to ministryofjustice/laa-fee-calculator that referenced this issue Feb 4, 2022
Latest version of setuptools is 60.7.1
https://setuptools.pypa.io/en/latest/history.html

Hopefully this has fixed the problem
pypa/setuptools#2352
jsugarman added a commit to ministryofjustice/laa-fee-calculator that referenced this issue Feb 4, 2022
Latest version of setuptools is 60.7.1
https://setuptools.pypa.io/en/latest/history.html

On build and deploy of this cahnge this appears to
have fixed the problem identified for setuptools
version 50, here:
pypa/setuptools#2352
jsugarman added a commit to ministryofjustice/laa-fee-calculator that referenced this issue Feb 4, 2022
Latest version of setuptools is 60.7.1
https://setuptools.pypa.io/en/latest/history.html

On build and deploy of this cahnge this appears to
have fixed the problem identified for setuptools
version 50, here:
pypa/setuptools#2352
nsaje added a commit to closeio/sync-engine that referenced this issue Jan 3, 2023
nsaje added a commit to closeio/sync-engine that referenced this issue Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet