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.

TypeError: dist must be a Distribution instance

See original GitHub issue

Description

when i run tests with nox -s test-3.9 -- -n auto tests/functional/test_bad_url.py -v

it is occurred an error, and can not passed. a lot of errors occurred when running the full number of test cases. i seek the answer on the internet, and some man say the reason is that setuptools is too new.

my setuptools is : 59.4.0

Expected behavior

it should be running test PASSED

pip version

21.3.1

Python version

3.9.9

OS

x86_64 linux

How to Reproduce

nox -s test-3.9 – -n auto tests/functional/test_bad_url.py -v

Output

nox > Running session test-3.9
nox > Re-using existing virtual environment at .nox/test-3-9.
nox > Re-using existing common-wheels at tests/data/common_wheels.
nox > python setup.py sdist --formats=zip --dist-dir /root/pip/.nox/test-3-9/sdist
nox > python tools/tox_pip.py install /root/pip/.nox/test-3-9/sdist/pip-21.3.1.zip
nox > python tools/tox_pip.py install -r tests/requirements.txt
nox > pytest -n auto tests/functional/test_bad_url.py -v
=============================================== test session starts ================================================
platform linux -- Python 3.9.9, pytest-7.1.2, pluggy-1.0.0 -- /root/pip/.nox/test-3-9/bin/python
cachedir: .pytest_cache
rootdir: /root/pip, configfile: setup.cfg
plugins: forked-1.4.0, rerunfailures-10.2, xdist-2.5.0, cov-3.0.0
[gw0] linux Python 3.9.9 cwd: /root/pip
[gw1] linux Python 3.9.9 cwd: /root/pip
[gw2] linux Python 3.9.9 cwd: /root/pip
[gw3] linux Python 3.9.9 cwd: /root/pip
[gw0] Python 3.9.9 (main, May 16 2022, 00:00:00)  -- [GCC 10.3.1]
[gw1] Python 3.9.9 (main, May 16 2022, 00:00:00)  -- [GCC 10.3.1]
[gw2] Python 3.9.9 (main, May 16 2022, 00:00:00)  -- [GCC 10.3.1]
[gw3] Python 3.9.9 (main, May 16 2022, 00:00:00)  -- [GCC 10.3.1]
gw0 [1] / gw1 [1] / gw2 [1] / gw3 [1]
scheduling tests via LoadScheduling

tests/functional/test_bad_url.py::test_filenotfound_error_message 
[gw0] [100%] ERROR tests/functional/test_bad_url.py::test_filenotfound_error_message 

====================================================== ERRORS ======================================================
________________________________ ERROR at setup of test_filenotfound_error_message _________________________________
[gw0] linux -- Python 3.9.9 /root/pip/.nox/test-3-9/bin/python

tmpdir_factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-root/pytest-43/popen-gw0'), ...luggy._tracing.TagTracerSub object at 0x7f64540d04f0>, _basetemp=PosixPath('/tmp/pytest-of-root/pytest-43/popen-gw0')))
common_wheels = Path('/root/pip/tests/data/common_wheels')

    @pytest.fixture(scope="session")
    def setuptools_install(
        tmpdir_factory: pytest.TempdirFactory, common_wheels: Path
    ) -> Path:
>       return _common_wheel_editable_install(tmpdir_factory, common_wheels, "setuptools")

tests/conftest.py:335: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/conftest.py:325: in _common_wheel_editable_install
    Wheel(wheel_candidates[0]).install_as_egg(install_dir)
.nox/test-3-9/lib/python3.9/site-packages/setuptools/wheel.py:96: in install_as_egg
    self._install_as_egg(destination_eggdir, zf)
.nox/test-3-9/lib/python3.9/site-packages/setuptools/wheel.py:104: in _install_as_egg
    self._convert_metadata(zf, destination_eggdir, dist_info, egg_info)
.nox/test-3-9/lib/python3.9/site-packages/setuptools/wheel.py:164: in _convert_metadata
    setup_dist.get_command_obj('egg_info'),
.nox/test-3-9/lib/python3.9/site-packages/setuptools/_distutils/dist.py:860: in get_command_obj
    cmd_obj = self.command_obj[command] = klass(self)
.nox/test-3-9/lib/python3.9/site-packages/setuptools/__init__.py:106: in __init__
    super().__init__(dist)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <setuptools.command.egg_info.egg_info object at 0x7f644fba3ee0>
dist = <setuptools.dist.Distribution object at 0x7f644fb859d0>

    def __init__(self, dist):
        """Create and initialize a new Command object.  Most importantly,
        invokes the 'initialize_options()' method, which is the real
        initializer and depends on the actual command being
        instantiated.
        """
        # late import because of mutual dependence between these classes
        from distutils.dist import Distribution
    
        if not isinstance(dist, Distribution):
>           raise TypeError("dist must be a Distribution instance")
E           TypeError: dist must be a Distribution instance

.nox/test-3-9/lib/python3.9/site-packages/setuptools/_distutils/cmd.py:57: TypeError
================================================= warnings summary =================================================
.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33
.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33
.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33
.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33
.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33
  /root/pip/.nox/test-3-9/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
    warnings.warn("Setuptools is replacing distutils.")

.nox/test-3-9/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: 540 warnings
  /root/pip/.nox/test-3-9/lib/python3.9/site-packages/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================= short test summary info ==============================================
ERROR tests/functional/test_bad_url.py::test_filenotfound_error_message - TypeError: dist must be a Distribution ...
========================================== 545 warnings, 1 error in 2.97s ==========================================
nox > Command pytest -n auto tests/functional/test_bad_url.py -v failed with exit code 1
nox > Session test-3.9 failed.

Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
pradyunsgcommented, Jul 23, 2022

Aha! Indeed, it does, yes.

IIRC, I’d added this because our tests started failing with this error when the new setuptools release came out which didn’t default that way, and none of us had the bandwidth to investigate what exactly had changed on setuptools’ end – especially how it interacted with our quirky test isolation setup.

1reaction
pfmoorecommented, Jul 23, 2022

Let’s put this another way. It’s not happening on anyone else’s system, so it’s fairly likely to be something about your system that’s the issue here. The information you’ve provided so far suggests that something outside of pip is causing the types not to match up. In our experience this is typically down to the complexities in how setuptools and distutils interact (which is something the setuptools team are familiar with, but we are not).

There’s nothing the pip team can do here. If you can demonstrate a bug in pip that can be reproduced on environments other than your own PC, then that would be useful. But the pip team can’t help you with that. The setuptools team might be able to - as I say, they are familiar with how the relevant interactions work - so you may get somewhere by reaching out to them. But you’re not going to make much progress asking here, as we’re the wrong people to ask.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: dist must be a Distribution instance - Stack Overflow
This error has to do with a discrepancy between the versions of distutils and setuptools installed on your machine.
Read more >
TypeError: dist must be a Distribution instance #539 - GitHub
When I run sh make.sh, then the following comes up, how can I overcome this problem? and my environment: Ubuntu18.04 Python3.7(Anoconda) ...
Read more >
raise TypeError, "dist must be a Distribution instance"
Hi all, I suddenly experience difficulties using Cython (ver. 0.21.1 on Arch Linux, Python 2.7.9) by the simple import pyximport; pyximport.install()
Read more >
Cpp_extension TypeError:dist must be a Distribution instance
Import Error: torchutils.ffi is deprecated. Please use cpp extensions instread. So, I make it import os import torch from torch.utils.ffi import ...
Read more >
"dist must be a Distribution instance" check fails with setuptools
distutils uses this code to validate the input in "Command. ... Distribution): raise TypeError, "dist must be a Distribution instance" ...
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