# 自动导入第三方库
# 导出已有的,pip freeze > D:\requirements.txt;导入未安装的,pip install -r D:\requirements.txt
def auto_import_lib(self, file_path=r"D:\Mytest\config\requirements.txt"):
import os
with open(file_path, "r+", encoding="utf-8") as f:
all_line = f.read().splitlines()
succese_list, fail_list = [], []
print("library_list:", str(all_line), "\n")
for i in all_line:
if "==" in str(i):
name = i.split("==")[0]
else:
name = i
print(f"----正在导入:{name}----\n")
try:
os.system(f'pip install {name}')
except Exception as e:
print('\033[0;31m' + 'Exception信息/行号/文件', e, e.__traceback__.tb_lineno, e.__traceback__.tb_frame.f_globals['__file__'] + '\033[0m')
fail_list.append(i)
succese_list = [val for val in all_line if val not in fail_list]
print(f"\n----成功{len(succese_list)}:{succese_list}----\n----失败{len(fail_list)}:{fail_list}----")
'''
----输出信息:
library_list: ['actions', 'Appium-Python-Client', 'atomicwrites', 'attrs', 'bcrypt', 'beautifulsoup4', 'bunch', 'certifi', 'cffi', 'chardet', 'colorama', 'configparser', 'cryptography', 'et-xmlfile', 'future', 'hypothesis', 'idna', 'importlib-metadata', 'jdcal', 'more-itertools', 'mysql', 'mysqlclient', 'numpy', 'openpyxl', 'packaging', 'pandas', 'parameterized', 'paramiko', 'Pillow', 'pluggy', 'poium', 'py', 'pycparser', 'Pygments', 'PyMySQL', 'PyNaCl', 'pyparsing', 'pypiwin32', 'PyPubSub', 'pytest', 'python-dateutil', 'python-gitlab', 'pytz', 'pywin32', 'requests', 'robotframework', 'robotframework-ride', 'robotframework-selenium2library', 'robotframework-seleniumlibrary', 'robotframeworklexer', 'seldom', 'selenium', 'six', 'soupsieve', 'tqdm', 'urllib3', 'wcwidth', 'wxPython', 'xlrd', 'xlwt', 'xlwt-future', 'zipp', 'pandas', 'pytest']
----正在导入:actions----
Requirement already satisfied: actions in d:\testfiles\python3\lib\site-packages (1.0.3)
Requirement already satisfied: bunch==1.0.1 in d:\testfiles\python3\lib\site-packages (from actions) (1.0.1)
----正在导入:Appium-Python-Client----
Requirement already satisfied: Appium-Python-Client in d:\testfiles\python3\lib\site-packages (1.0.2)
Requirement already satisfied: selenium<4,>=3.14.1 in d:\testfiles\python3\lib\site-packages (from Appium-Python-Client) (3.141.0)
Requirement already satisfied: urllib3 in d:\testfiles\python3\lib\site-packages (from selenium<4,>=3.14.1->Appium-Python-Client) (1.25.10)
'''
actions
Appium-Python-Client
atomicwrites
attrs
bcrypt
beautifulsoup4
bunch
certifi
cffi
chardet
colorama
configparser
cryptography
et-xmlfile
future
hypothesis
idna
importlib-metadata
jdcal
more-itertools
mysql
mysqlclient
numpy
openpyxl
packaging
pandas
parameterized
paramiko
Pillow
pluggy
poium
py
pycparser
Pygments
PyMySQL
PyNaCl
pyparsing
pypiwin32
PyPubSub
pytest
python-dateutil
python-gitlab
pytz
pywin32
requests
robotframework
robotframework-ride
robotframework-selenium2library
robotframework-seleniumlibrary
robotframeworklexer
seldom
selenium
six
soupsieve
tqdm
urllib3
wcwidth
wxPython
xlrd
xlwt
xlwt-future
zipp
pandas
pytest