赞
踩
PyP
I和pip
是两个不同的概念,但它们是密切相关的。
PyPI(Python Package Index)是一个Python软件包仓库,Python开发人员可以在其中发布、分享和下载Python软件包。开发人员可以使用Web界面或命令行工具上传软件包到PyPI,然后其他开发人员就可以使用pip(Python Package Installer)这个包管理工具从PyPI上下载和安装软件包。
官方:https://pypi.org/simple
清华:https://pypi.tuna.tsinghua.edu.cn/simple
百度:https://mirror.baidu.com/pypi/simple/
阿里:https://mirrors.aliyun.com/pypi/simple/
豆瓣:https://pypi.douban.com/simple/
中科大:https://pypi.mirrors.ustc.edu.cn/simple/
pip install xxx -i https://pypi.tuna.tsinghua.edu.cn/simple
大体分为以下步骤:
/mirror/pip
,用于存储pypi文件,作为仓库目录/mirror/pip
dnf install -y python
pip3 install pip2pi
/mirror/pip
,用于存储pypi文件,作为仓库目录mkdir /mirror
mkdir /mirror/pip
/mirror/pip
touch requirement.py
import requests
import re
report = requests.request('get','https://mirrors.bfsu.edu.cn/pypi/web/simple')
# print(report.text)
text_str = str(report.text).split('\n')
with open('requirement.txt','w+') as f:
for i in text_str:
temp = re.findall('<a href="(.*?)/">',i)
# print(i,temp)
if temp != []:
f.write(str(temp[0])+'\n')
touch download.py
import os file="./requirement.txt" #使用 with 语句可以避免忘记关闭文件而导致的资源泄露问题。 #open(file, 'r+'):这是调用 open() 函数来打开文件。file 是文件路径和名称的字符串,'r+'模式表示文件以读写模式打开 #as f:这表示将打开的文件对象赋值给变量 f,你可以在随后的代码块中使用这个变量来操作文件。 with open(file,'r+') as f: text = f.readlines() for i in text: if not os.path.exists(i[:-1]): #i[:-1] 是一个Python的切片操作,它返回字符串 i 的所有字符,除了最后一个。(在Windows上是\,在大多数其他系统上是/) os.mkdir(i[:-1]) os.system('pip download '+i[:-1]+' -i https://mirrors.bfsu.edu.cn/pypi/web/simple -d '+i[:-1]) else: print(f"{i[:-1]} 文件夹已存在,本次跳过。")
cd /mirror/pip
python requirement.py
cd /mirror/pip
python download.py
详见:https://blog.csdn.net/xzzteach/article/details/137182578
第四点
临时配置:
pip install django -i http://192.168.200.8/
永久配置:
pip config set global.index-url http://192.168.200.8/
pip install django
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。