2

There are some parts of the nltk corpus that I'd like to add to the setup.py file. I followed the response here by setting up a custom cmdclass. My setup file looks like this.


from setuptools import setup
from setuptools.command.install import install as _install


class DownloadNLTK(install):
    def run(self):
        self.do_egg_install()
        import nltk
        nltk.download('wordnet')
        nltk.download('punkt')
        nltk.download('stopwords')
        nltk.download('vader_lexicon')

setup(
    install_requires=requirements,
    python_requires='>=3.7',
    cmdclass={'download_nltk': DownloadNLTK()}
)

However, running it, I get this error:

Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    'install': DownloadNLTK()}
TypeError: __init__() missing 1 required positional argument: 'dist'

I tried to better understand what's needed, but I have to say that the documentation I found here on dist is not very clear to me. Can someone help with a solution approach? Thanks!

mizzlosis
  • 515
  • 1
  • 4
  • 17
  • 1
    Your indentation is clearly wrong; please [edit] to fix it. On the desktop version of this site, you can get code marked up for you by pasting your code, selecting the pasted block, and typing ctrl-K. – tripleee Jun 03 '21 at 12:11
  • You seem to be referring to the documentation for `distutils` which is separate from `seetuptools`. Looking at the example you are copying from, the `cmdclass` dict value should probably be a class, not a function call returning an instance of that class (so take out the final `()`); but I have not tried your code, and don't really understand what it's supposed to do. – tripleee Jun 03 '21 at 12:13

1 Answers1

1

Pass the class, not its instance:

    cmdclass={'download_nltk': DownloadNLTK}

(no () to avoid instantiating the class)

phd
  • 82,685
  • 13
  • 120
  • 165