How do I require Tkinter with distutils?

前端 未结 3 1560

I\'m trying to compile a program using distutils but I want to make sure that the user has Tkinter installed before installing my package.

My Google searche

3条回答
  •  离开以前
    2021-01-22 12:19

    You can have a class that inherits from install and then do this:

    from distutils.command.install import install
    
    class Install(install):
        def run(self):
            if not check_dependencies():
                 # Tkinter was not installed, handle this here
            install.run(self) # proceed with the installation
    
    def check_dependencies():
        try:
            return __import__('Tkinter')
        except ImportError:
            return None
    

提交回复
热议问题