Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-install missing python modules
import sys
import pip
from importlib import import_module
from importlib.abc import MetaPathFinder
class PipMetaPathFinder(MetaPathFinder):
"""A importlib.abc.MetaPathFinder to auto-install missing modules using pip
"""
def find_spec(fullname, path, target=None):
if path == None:
installed = pip.main(['install', fullname])
if installed == 0:
return import_module(fullname)
sys.meta_path.append(PipMetaPathFinder)
@KaizArafat4321
Copy link

My python compiler is saying that Attribution error: 'list' object has no attribute 'append'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment