Created
November 1, 2023 22:35
-
-
Save Melodi17/a84a781d07adb4ff97b84725a577a43e to your computer and use it in GitHub Desktop.
This file contains 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
from __future__ import division | |
_lib_valid_sys_paths = [ | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\DLLs', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\lib', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32\\lib', | |
'C:\\Users\\{user}\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\Pythonwin' | |
] | |
_lib_attempted_installed_modules = [] | |
while True: | |
try: | |
import subprocess | |
import ast | |
import bs4 | |
import base64 | |
import datetime | |
import json | |
import math | |
import os | |
import platform | |
import random | |
import re | |
import string | |
import sys | |
import time | |
import webbrowser | |
import requests | |
import pyautogui | |
import screen_brightness_control | |
import ctypes | |
import pyautogui | |
import cryptography.fernet | |
import plyer | |
import plyer.utils | |
import csv | |
import enum | |
import pyparsing | |
import math | |
import operator | |
import global_hotkeys | |
import atexit | |
import itertools | |
import shutil | |
import signal | |
import winreg | |
import types | |
import multiprocessing.pool | |
import pythoncom | |
import win32api | |
import tabulate | |
break | |
except Exception as e: | |
if isinstance(e, ModuleNotFoundError): | |
try: | |
sys_module = __import__('sys') | |
os_module = __import__('os') | |
except ModuleNotFoundError as mod_error: | |
print(f'[lib.py] ModuleNotFoundError: missing module \'{mod_error.name}\', this module is a core ' | |
f'requirement, giving up') | |
exit(-1) | |
for i in _lib_valid_sys_paths: | |
ci = i.replace('{user}', os_module.getenv('USERNAME')) | |
if ci not in sys_module.path: | |
print(f'[lib.py] PathMismatchError: the python environment path seems to be missing \'{ci}\', ' | |
f'attempting automatic repair') | |
sys_module.path.append(ci) | |
continue | |
if e.name in _lib_attempted_installed_modules: | |
print(f'[lib.py] ModuleNotFoundError: missing module \'{e.name}\', install already attempted, giving up') | |
exit(-1) | |
else: | |
_lib_attempted_installed_modules.append(e.name) | |
print(f'[lib.py] ModuleNotFoundError: missing module \'{e.name}\', attempting automatic repair') | |
if 'subprocess' not in locals(): | |
print(f'[lib.py] ModuleNotFoundError: missing module \'subprocess\', this module is a core ' | |
f'requirement, giving up') | |
exit(-1) | |
op = subprocess.getoutput('pip install ' + e.name).replace('\r', '') | |
print('\n'.join(['\t- ' + i for i in op.split | |
('\n')])) | |
if 'requirement already satisfied' in op.lower(): | |
mpath = op.split('\n')[0].lower().partition(' in ')[2].partition(' (')[0] | |
sr = [i.lower() for i in sys_module.path] | |
if mpath not in sr: | |
print(f'[lib.py] PathMismatchError: detected pip installed \'{e.name}\' into {mpath} which is ' | |
f'not accessible by python, attempting automatic repair') | |
sys_module.path.append(mpath) | |
else: | |
print(f'[lib.py] PathMatched: detected pip installed \'{e.name}\' into {mpath} which is ' | |
f'accessible by python') | |
# main code below |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment