Skip to content

Instantly share code, notes, and snippets.

@lonetwin
Created May 16, 2016 13:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonetwin/b97e7b35634f7229773dece3735cfb58 to your computer and use it in GitHub Desktop.
Save lonetwin/b97e7b35634f7229773dece3735cfb58 to your computer and use it in GitHub Desktop.
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