AlexLordThorsen
AlexLordThorsen

Reputation: 8488

python setup.py sdist bdist_wheel raises `TypeError: expected string or bytes-like object`

Problem Statement

When setting packages= to [find_packages()] I'm hitting a TypeError. When setting the packages variable directly to the resulting string ("spark_jobs") I no longer hit the unexpected exception. I was wondering if anyone understands what's happening here.

for reference I'm running on python 3.9.

setup.py

  setup(
      name=f"{PROJECT_NAME}",
      version=f"{VERSION}",
      description="f{PROJECT_DESCRIPTION}",
      long_description=README,
      long_description_content_type="text/markdown",
      url=f"{url}",
      author=f"{author}",
      classifiers=[
          "Programming Language :: Python :: 3",
          "Programming Language :: Python :: 3.7",
          "Programming Language :: Python :: 3.8",
          "Programming Language :: Python :: 3.9",
      ],
      packages=[find_packages()],
      include_package_data=True,
      install_requires=INSTALL_REQUIRES,
      tests_require=TESTS_REQUIRE,
  )

Error

python setup.py sdist bdist_wheel
Traceback (most recent call last):
  File "setup.py", line 40, in <module>
    setup(
  File "/Users/alexlordthorsen/.venvs/data_platform/lib/python3.8/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/Users/alexlordthorsen/.venvs/data_platform/lib/python3.8/site-packages/setuptools/dist.py", line 445, in __init__
    _Distribution.__init__(self, {
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 292, in __init__
    self.finalize_options()
  File "/Users/alexlordthorsen/.venvs/data_platform/lib/python3.8/site-packages/setuptools/dist.py", line 734, in finalize_options
    ep.load()(self, ep.name, value)
  File "/Users/alexlordthorsen/.venvs/data_platform/lib/python3.8/site-packages/setuptools/dist.py", line 329, in check_packages
    if not re.match(r'\w+(\.\w+)*', pkgname):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/re.py", line 189, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object

Setting A Breakpoint

When I setup a breakpoint I found that the results was a list with a single string.

(Pdb) find_packages()
['spark_jobs']

which, confusingly, if I set packages=['spark-jobs'] directly I no longer hit the above error but I also get an empty

Upvotes: 1

Views: 1631

Answers (1)

phd
phd

Reputation: 94453

find_packages() already returns a list, you don't need to wrap it in another list. The correct syntax is just

  packages=find_packages(),

In packages=['spark-jobs'] the package name must be spelled exactly like the directory (and the directory name must follow Python name rules) so fix it as

packages=['spark_jobs']

Upvotes: 1

Related Questions