Search code examples
pythonpython-3.xsetuptools

setuptools giving `TypeError` for minimal setup.py example


I'm trying to troubleshoot an issue I've been having with setuptools. Even with this minimal setup.py example, I get the following error:

setup.py

from setuptools import setup
setup(
    name="packagename"
)

Running python setup.py:

Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    setup(
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/__init__.py", line 86, in setup
    _install_setup_requires(attrs)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/__init__.py", line 75, in _install_setup_requires
    dist = MinimalDistribution(attrs)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/__init__.py", line 57, in __init__
    super().__init__(filtered)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/dist.py", line 474, in __init__
    for ep in metadata.entry_points(group='distutils.setup_keywords'):
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 999, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 449, in load
    ordered = sorted(eps, key=by_group)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 996, in <genexpr>
    eps = itertools.chain.from_iterable(
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/_itertools.py", line 16, in unique_everseen
    k = key(element)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 931, in _normalized_name
    return self._name_from_stem(stem) or super()._normalized_name
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 600, in _normalized_name
    return Prepared.normalize(self.name)
  File "/home/user/anaconda3/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 855, in normalize
    return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
  File "/home/user/anaconda3/lib/python3.8/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

I'm using Python 3.8.13 and setuptools 65.4.1. I've tried uninstalling and reinstalling setuptools with pip.


Solution

  • The issue ended up being an improperly uninstalled package. See, for example, this answer detailing how to remove a package installed with python setup.py install. Neglecting to delete the containing directory results in the error described here.