question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setuptools 50 fails with `KeyError: 'distutils'` when installing some packages

See original GitHub issue

I got the following error when tried to install doit.

$ pip install doit
Collecting doit
  Using cached doit-0.32.0.tar.gz (1.4 MB)
    ERROR: Command errored out with exit status 1:
     command: /home/enki/projects/.../.venv/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-t_g4mfyi/doit/setup.py'"'"'; __file__='"'"'/tmp/pip-install-t_g4mfyi/doit/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-shhwaq7f
         cwd: /tmp/pip-install-t_g4mfyi/doit/
    Complete output (17 lines):
    /home/enki/projects/.../.venv/lib/python3.6/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
      warnings.warn("Setuptools is replacing distutils.")
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-t_g4mfyi/doit/setup.py", line 88, in <module>
        'doit = doit.__main__:main'
      File "/home/enki/projects/.../.venv/lib/python3.6/site-packages/setuptools/__init__.py", line 152, in setup
        _install_setup_requires(attrs)
      File "/home/enki/projects/.../.venv/lib/python3.6/site-packages/setuptools/__init__.py", line 145, in _install_setup_requires
        dist.parse_config_files(ignore_option_errors=True)
      File "/home/enki/projects/.../.venv/lib/python3.6/site-packages/setuptools/dist.py", line 665, in parse_config_files
        self._parse_config_files(filenames=filenames)
      File "/home/enki/projects/.../.venv/lib/python3.6/site-packages/setuptools/dist.py", line 572, in _parse_config_files
        filenames = self.find_config_files()
      File "/home/enki/projects/.../.venv/lib/python3.6/site-packages/setuptools/_distutils/dist.py", line 353, in find_config_files
        sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
    KeyError: 'distutils'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
asfaltboycommented, Aug 31, 2020

Could this be a side-effect of overriding distutils on stdlib the as described in #2350? I’ll try to confirm the workaround (using SETUPTOOLS_USE_DISTUTILS=1 works and report back).

EDIT: the workaround worked fine, as long as I run it before installing python via apt-get / get-pip installations .

1reaction
jaracocommented, Sep 5, 2020

According to using pip in your program, import pip is not supported anywhere.

#2381 takes some steps to avoid breaking under the conditions where pip is imported.

And if it’s not supported, should it simply fail (maybe with some environment detection) instead of asking why people uses an unsupported code later?

Perhaps that’s a question for the pip maintainers. My instinct is that users should be allowed to “import pip” at their own risk, so it shouldn’t be strictly enforced.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python distutils keyError - setuptools - Stack Overflow
I downgraded to setuptools==58.2.0 and now it works fine again.
Read more >
setuptools 1.1.1 - PyPI
Easily download, build, install, upgrade, and uninstall Python packages.
Read more >
python _distutils_hack | The AI Search Engine You Control
The problem is caused by setuptools 60.x's _distutils_hack. Please report the issue to setuptools or use SETUPTOOLS_USE_DISTUTILS ...
Read more >
Build and install error messages - TensorFlow
If you find an installation or build problem that is not listed, please search the ... Installing collected packages: setuptools, protobuf, wheel, numpy, ......
Read more >
5.6.5 : The module configuration : setup.py - LAPP
Check is Cython package is installed. The Cython package makes the python extensions for wrappers. 1 2 3 4 5 6 7 8,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found