【Web_接口测试_Python3_自动导入已知库】pip install ***批量自动导入常用的第三方库

    # 自动导入第三方库
    # 导出已有的,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

2020-12-10
actions==1.0.3
allure-pytest==2.8.24
allure-python-commons==2.8.24
altgraph==0.17
Appium-Python-Client==1.0.2
atomicwrites==1.4.0
attrs==20.2.0
bcrypt==3.2.0
beautifulsoup4==4.9.1
bunch==1.0.1
certifi==2020.6.20
cffi==1.14.2
chardet==3.0.4
colorama==0.4.3
configparser==5.0.0
cryptography==3.1
ddt==1.4.1
et-xmlfile==1.0.1
fake-useragent==0.1.11
future==0.18.2
gitdb==4.0.5
GitPython==3.1.11
html-testRunner==1.2.1
idna==2.10
importlib-metadata==1.7.0
iniconfig==1.0.1
jdcal==1.4.1
Jinja2==2.11.2
jsonpath==0.82
jsonschema==3.2.0
MarkupSafe==1.1.1
more-itertools==8.5.0
multi-key-dict==2.0.3
mysql==0.0.2
mysqlclient==2.0.1
openpyxl==3.0.5
packaging==20.4
parameterized==0.7.0
paramiko==2.7.2
pbr==5.5.1
pefile==2019.4.18
pluggy==0.13.1
poium==0.6.4
prettytable==0.7.2
py==1.9.0
pycparser==2.20
pyinstaller==4.0
pyinstaller-hooks-contrib==2020.9
PyMySQL==0.10.1
PyNaCl==1.4.0
pyparsing==2.4.7
Pypubsub==4.0.3
pyrsistent==0.17.3
pytest @ file:///D:/360Downloads/Software/pytest-6.0.2-py3-none-any.whl
python-dateutil==2.8.1
python-gitlab==2.5.0
python-jenkins==1.7.0
pytz==2020.1
pywin32-ctypes==0.2.0
PyYAML==5.3.1
requests==2.24.0
robotframework==3.2.2
robotframework-pythonlibcore==2.1.0
robotframework-selenium2library==3.0.0
robotframework-seleniumlibrary==4.5.0
robotframeworklexer==1.1
seldom==1.6.0
selenium==3.141.0
six==1.15.0
smmap==3.0.4
soupsieve==2.0.1
toml==0.10.1
tqdm==4.49.0
unittest-xml-reporting==3.0.4
urllib3==1.25.10
wcwidth==0.2.5
xlrd==1.2.0
xlwt==1.3.0
xlwt-future==0.8.0
zipp==3.1.0


 

猜你喜欢

转载自blog.csdn.net/denzeleo/article/details/108572565
今日推荐