Search code examples
pythonnltksetuptoolssetup.py

download nltk corpus as cmdclass in setup.py files not working


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!


Solution

  • Pass the class, not its instance:

        cmdclass={'download_nltk': DownloadNLTK}
    

    (no () to avoid instantiating the class)