From c01590aba8de175d6f601f18e37c7f7c72fb0b7b Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:22:06 +0000 Subject: [PATCH] add autopip.py --- autopip.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 autopip.py diff --git a/autopip.py b/autopip.py new file mode 100644 index 0000000..7c5f713 --- /dev/null +++ b/autopip.py @@ -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