【准备】
1、环境
centso7系统、已有python环境,能连接外网和内网
2、安装pip
yum install -y epel-release
yum install -y python-pip
【开始安装】
1、本地安装pip2pi
pip install pip2pi
2、创建镜像源仓库位置目录
mkdir -p /home/pip_source
3、将需要的依赖包上传到当前目录下或下载同步软件包
单个包同步:
pip2tgz /home/pip_source pytest
批量同步:
pip2tgz /home/pip_source -r requirements.txt
查看同步的包:
ls -l /home/pip_source/
4、建立依赖包索引
dir2pi /home/pip_source/
5、配置nginx,让其他机子使用(默认路径/usr/local/nginx/conf)
# pip_source
server {
listen 8082;
server_name localhost;
charset utf-8,gbk;
location / {
root /home/pip_source;
autoindex on;
autoindex_exact_size off; #显示文件的大小
autoindex_localtime on; #显示文件时间
}
access_log logs/pip.log;
}
6、重载或重启nginx
service nginx restart
7、测试
访问地址:ip:8082
内网测试:pip3 install --index-url=http://ip:8082/simple/ --trusted-host=ip django==3.2.0
【windows内网使用】
1、配置pip文件
C盘-->用户-->admin(自己的账户名)
新建pip文件夹,pip文件夹下新建pip.ini文件
2、写入以下内容
[global]
index-url = http://192.168.16.101:8082/simple
[install]
trusted-host = 192.168.16.101
3、使用
pip3 install pytest