简介
pip是python的一个包管理工具,安装完python后就会自带有pip管理工具。
主要记录下pip3的使用和配置方法。
使用
1 2 3
| $ pip3 install <pacakge> $ pip3 install -v <pacakge>==<verison> $ python -m pip3 install <pacakge>
|
1
| $ pip3 uninstall <pacakge>
|
1 2
| $ pip3 list $ pip3 freeze
|
1
| $ pip3 install --upgrade <package>
|
1
| $ pip3 install --upgrade pip3
|
配置
- 修改仓库镜像源地址
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 26 27 28 29 30 31
| """ 自动创建pip.ini文件脚本
修改配置文件实现 # Windows: C:/Users/<用户名>/pip/pip.ini # Linux: ~/.pip/pip.conf
国内的其他镜像源 清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/ 阿里云: http://mirrors.aliyun.com/pypi/simple/ 中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣: http://pypi.douban.com/simple/ 中国科学技术大学: http://pypi.mirrors.ustc.edu.cn/simple/ """
import os
content = """[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ [install] trusted-host=pypi.tuna.tsinghua.edu.cn """
pipPath = os.environ["USERPROFILE"] + "\\pip\\" if not os.path.exists(pipPath): os.mkdir(pipPath)
with open(pipPath + "pip.ini", "w+") as f: f.write(content)
|
设置成功后可以看到:
![](/images/blog/202304/16822609145NWi4.png)