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

pkg_resources: UnboundLocalError: local variable 'dist' referenced before assignment #702

The-Compiler opened this issue Jul 29, 2016 · 6 comments · Fixed by #703


Copy link

When trying to run my package's tests frozen via cx_Freeze on Windows, I just got this:

  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\pkg_resources\", line 2986, in _initialize_master_working_set
    del dist
UnboundLocalError: local variable 'dist' referenced before assignment

full traceback:

unittests-frozen runtests: commands[2] | C:\projects\qutebrowser\.tox\unittests-frozen/build/run-frozen-tests
Traceback (most recent call last):
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\cx_Freeze\initscripts\", line 27, in <module>
    exec(code, m.__dict__)
  File "scripts/dev/", line 38, in <module>
    pytest_rerunfailures, pytest_warnings]))
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 39, in main
    config = _prepareconfig(args, plugins)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 118, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 249, in _wrapped_call
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 28, in pytest_cmdline_parse
    config = outcome.get_result()
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 278, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 264, in __init__
    self.result = func()
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 596, in execute
    res = hook_impl.function(*args)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 861, in pytest_cmdline_parse
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 966, in parse
    self._preparse(args, addopts=addopts)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\", line 927, in _preparse
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\_pytest\vendored_packages\", line 495, in load_setuptools_entrypoints
    from pkg_resources import iter_entry_points, DistributionNotFound
  File "c:\python\32-bit\3.4\lib\importlib\", line 2237, in _find_and_load
  File "c:\python\32-bit\3.4\lib\importlib\", line 2226, in _find_and_load_unlocked
  File "c:\python\32-bit\3.4\lib\importlib\", line 1191, in _load_unlocked
  File "c:\python\32-bit\3.4\lib\importlib\", line 1161, in _load_backward_compatible
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\pkg_resources\", line 2958, in <module>
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\pkg_resources\", line 2944, in _call_aside
    f(*args, **kwargs)
  File "C:\projects\qutebrowser\.tox\unittests-frozen\lib\site-packages\pkg_resources\", line 2986, in _initialize_master_working_set
    del dist
UnboundLocalError: local variable 'dist' referenced before assignment

This seems to be introduced in #698 (cc @minrk) and happens when the for dist in working_set: above doesn't assign to dist because working_set is empty.

Copy link

minrk commented Jul 29, 2016

Fixed by #703. Sorry about that, and thanks for catching it!

Copy link

No worries, that was a mean one, probably wouldn't have noticed it either. Thanks for the quick fix!

Copy link

destijl commented Aug 1, 2016

Thanks for fixing this, just hit it myself. I see that 25.1.2 includes this fix and is tagged on github but isn't released on pypi? If you're expecting to get that onto pypi soon I can probably avoid having to go through all my install scripts pinning the setuptools version. Any idea when that might happen?

Copy link

jaraco commented Aug 1, 2016

Hmm. PyPI releases are meant to be automatic from tagged versions. Let's see what happened.

Aah, so it built and tests passed, but the upload failed because I forgot to bump the versions in the code (by running bumpversion patch) first.

I'll push out a release momentarily.

Copy link

jaraco commented Aug 1, 2016

I expect the release to go out with this job.

Copy link

destijl commented Aug 1, 2016

Great, it's out, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging a pull request may close this issue.

4 participants