forked from Jxb0123/QRabbitPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRabbit.py
More file actions
25 lines (22 loc) · 968 Bytes
/
Copy pathRabbit.py
File metadata and controls
25 lines (22 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import subprocess
import pkg_resources
from pkg_resources import parse_requirements, DistributionNotFound
# 读取requirements.txt文件中的所有库
with open('requirements.txt') as f:
requirements = parse_requirements(f.read())
# 安装缺失的库,或者安装新版本的库
for requirement in requirements:
try:
module_name = requirement.name
if requirement.specifier:
required_version = str(requirement.specifier)
installed_version = pkg_resources.get_distribution(module_name).version
if installed_version not in required_version:
subprocess.check_call(['pip', 'install', f"{module_name}{required_version}"])
else:
__import__(module_name)
except (DistributionNotFound, pkg_resources.VersionConflict, ModuleNotFoundError):
subprocess.check_call(['pip', 'install', str(requirement)])
from sanic_app import main
if __name__ == "__main__":
main()