add autopip.py
This commit is contained in:
66
autopip.py
Normal file
66
autopip.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# autopip.py
|
||||
|
||||
import os, builtins
|
||||
|
||||
old_import = builtins.__import__
|
||||
|
||||
def new_import(name, globals=None, locals=None, fromlist=(), level=0):
|
||||
import_to_pip = {
|
||||
"skimage": "scikit-image",
|
||||
"sklearn": "scikit-learn",
|
||||
"bs4": "beautifulsoup4",
|
||||
"PIL": "pillow",
|
||||
"yaml": "PyYAML",
|
||||
"cv2": "opencv-python",
|
||||
"Crypto": "pycryptodome",
|
||||
"MySQLdb": "pymysql",
|
||||
"jose": "python-jose",
|
||||
"dotenv": "python-dotenv",
|
||||
"jwt": "PyJWT",
|
||||
"magic": "python-magic",
|
||||
"Cryptodome": "pycryptodomex",
|
||||
"dateutil": "python-dateutil",
|
||||
"markupsafe": "MarkupSafe",
|
||||
"pywt": "PyWavelets",
|
||||
"httplib2": "httplib2",
|
||||
"serial": "pyserial",
|
||||
"Image": "Pillow",
|
||||
"cairo": "pycairo",
|
||||
"mx.DateTime": "egenix-mx-base",
|
||||
"cocos": "cocos2d",
|
||||
"zmq": "pyzmq",
|
||||
"MySQLdb": "mysqlclient",
|
||||
"lxml.etree": "lxml",
|
||||
"lxml.objectify": "lxml",
|
||||
"wx": "wxPython",
|
||||
"gi": "PyGObject",
|
||||
"enchant": "pyenchant",
|
||||
"tkSnack": "python-tksnack",
|
||||
"gflags": "python-gflags",
|
||||
"glog": "glog",
|
||||
"leveldb": "plyvel",
|
||||
"OpenGL": "PyOpenGL",
|
||||
"OpenGL.GL": "PyOpenGL",
|
||||
"OpenGL.GLU": "PyOpenGL",
|
||||
"OpenGL.GLUT": "PyOpenGL",
|
||||
"gevent.monkey": "gevent",
|
||||
"netifaces": "netifaces",
|
||||
"netCDF4": "netCDF4",
|
||||
"netaddr": "netaddr",
|
||||
"netCDF4_utils": "netCDF4",
|
||||
"rasterio": "rasterio",
|
||||
"gdal": "GDAL",
|
||||
"osgeo": "GDAL",
|
||||
"osr": "GDAL",
|
||||
"ogr": "GDAL",
|
||||
"pycurl": "pycurl",
|
||||
"pygments": "Pygments",
|
||||
"pydot": "pydot"
|
||||
}
|
||||
|
||||
try: return old_import(name, globals, locals, fromlist, level)
|
||||
except ImportError as e:
|
||||
if name[0] != '_':
|
||||
os.system(f'pip install -q {import_to_pip.get(name, name)}')
|
||||
|
||||
builtins.__import__ = new_import
|
||||
Reference in New Issue
Block a user