Created
May 16, 2016 13:15
-
-
Save lonetwin/b97e7b35634f7229773dece3735cfb58 to your computer and use it in GitHub Desktop.
Auto-install missing python modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My python compiler is saying that Attribution error: 'list' object has no attribute 'append'