How to check if a module is installed in Python and, if not, install it within the code?

后端 未结 7 1953
失恋的感觉
失恋的感觉 2021-01-31 17:35

I would like to install the modules \'mutagen\' and \'gTTS\' for my code, but I want to have it so it will install the modules on every computer that doesn\'t have them, but it

相关标签:
7条回答
  • 2021-01-31 17:54

    Another solution it to put an import statement for whatever you're trying to import into a try/except block, so if it works it's installed, but if not it'll throw the exception and you can run the command to install it.

    0 讨论(0)
提交回复
热议问题