python 常用命令合集

一.pip类
1.安装依赖
pip install -r requirement.txt

-r:安装requirement.txt文件中的依赖

2.查看某个包是否安装
pip list |grep opencv-python

3.安装包
pip3 install opencv-python

二.报错类
1.SSL报错
现象:
Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(“hostname

解决:

res = requests.get(url,verify=False)

2.ua报错
现象:
FakeUserAgentError(‘Maximum amount of retries reached’)
解决:

from fake_useragent import UserAgent
def header_fake():
file_path = os.getcwd() + ‘/useragent_fake.json’
ua_fake = UserAgent(path=file_path)
return ua_fake.random

json文件地址:
https://github.com/yesterday808/python_sets/blob/master/useragent_fake.json