fix: requirements install

This commit is contained in:
omg-xtao 2024-02-14 14:14:53 +00:00 committed by GitHub
parent 11df6fde31
commit ae175f4d72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,10 @@ from typing import List, Dict, Optional
import asyncpg import asyncpg
from .utils import pip_install
pip_install("cashews")
from cashews import cache from cashews import cache
from telethon import TelegramClient from telethon import TelegramClient
from telethon.errors import StatsMigrateError from telethon.errors import StatsMigrateError

18
utils.py Normal file
View File

@ -0,0 +1,18 @@
from typing import Optional
import subprocess
from sys import executable
from importlib.util import find_spec
def pip_install(
package: str, version: Optional[str] = "", alias: Optional[str] = ""
) -> bool:
"""Auto install extra pypi packages"""
if not alias:
# when import name is not provided, use package name
alias = package
if find_spec(alias) is None:
subprocess.call([executable, "-m", "pip", "install", f"{package}{version}"])
if find_spec(package) is None:
return False
return True