内网建自己的pip源

内网建自己的pip源

  • [一. 下载数据包](#一. 下载数据包)
  • [二. 建立索引](#二. 建立索引)
  • [三. 安装nginx](#三. 安装nginx)
  • [四. 配置nginx](#四. 配置nginx)
  • 五.展示

一. 下载数据包

以清华源为示例

cpp 复制代码
import requests
import bs4
import re
import wget
a = requests.get("https://pypi.tuna.tsinghua.edu.cn/simple").text
b = bs4.BeautifulSoup(a, "html.parser")
s = b.find_all("a")
count=0
with open("/Users/dongxiang/code/whl/pypi.txt", "w") as f:
   for i in range(len(s)):
      tree=requests.get("https://pypi.tuna.tsinghua.edu.cn/simple/"+s[i].text ).text
      tree_parser = bs4.BeautifulSoup(tree, "html.parser")
      real_name = tree_parser.find_all("a")
      for i in range(len(real_name)):
         ##print(str(real_name[i].text )+ "\n",str(count))
         count=count+1
         whlname=real_name[i].text
         ###此处只下载python3.10版本的whl
         if (re.findall(r'cp310', whlname) or re.findall(r'none-any', whlname) )and re.findall(r'.*\.whl', whlname) :
            #print(real_name[i].text+" URL:https://pypi.tuna.tsinghua.edu.cn/simple/"+real_name[i].attrs['href']+"\n")
            #f.write(real_name[i].text+" URL:https://pypi.tuna.tsinghua.edu.cn/simple/"+real_name[i].attrs['href']+"\n")
            wget.download("https://pypi.tuna.tsinghua.edu.cn/simple/s[i].text/"+real_name[i].attrs['href'],"/Users/dongxiang/code/whl"+real_name[i].text)
f.close()

二. 建立索引

需要先安装python,最好创建虚拟环境。参考我的另一个文章。

本地安装pip2pi

cpp 复制代码
pip install pip2pi

命令行切换到下载的 .whl文件夹,建立索引(自动生成了index.html)

cpp 复制代码
dir2pi -S 【某文件夹】此处为/Users/dongxiang/code/whl

然后文件夹内就出现了一个simple文件夹,这里的内容就和阿里、清华、豆瓣的源差别没那么大了。

注意如果是在Linux 环境下,这个S 要用小写的。

三. 安装nginx

不同的系统环境安装方式不同,具体可以网上查找即可。

  • Linux :
cpp 复制代码
yum install nginx

第一步: yum install nginx

安装命令执行完等待安装完成即可

第二步: cd /etc/nginx

安装完成后nginx的目录

第三步: service nginx start

如果访问不了,可能是防火墙问题

cpp 复制代码
添加 --permanent永久生效,没有此参数重启后失效 这里的6379为redis服务的端口,若为其他服务设置,需要对应端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent 
重新载入
firewall-cmd --reload
查看所有打开的端口: 
firewall-cmd --zone=public --list-ports
防火墙的关闭: 
systemctl stop firewalld	//一般不用
防火墙的启动: 
systemctl start firewalld

查看安装目录

rpm -ql nginx

4、运行起来,就可以直接输入 ip 地址查看了,端口默认是 80

sudo service nginx start

5、nginx 默认配置文件的路径

/usr/local/nginx/nginx-1.13.7/conf

或者

/etc/nginx/nginx.conf

停止 nginx:nginx.exe -s stop

重新加载:nginx.exe -s reload

退出:nginx.exe -s quit

  • Windows:
    直接解压压缩包到指定位置即可。

四. 配置nginx

修改/etc/nginx/nginx.conf配置文件

Windows版

修改nginx.conf

cpp 复制代码
server { 
	listen 8888; 
	# server_name 10.10.2.33:8888; 
	server_name 127.0.0.1:8888; 
	charset utf-8; 
	location / { 
	root C:/develop/Projects/pypip/whl/simple;
	autoindex on; 
	autoindex_exact_size off; #显示文件的大小
	autoindex_localtime on; #显示文件时间 
	#limit_rate_after 5m; #5分钟后下载速度限制为200k 
	#limit_rate 200k;
	} 
	access_log logs/pip.log; 
	}

linux 参照这个修改即可。

五.展示

相关推荐
DogDaoDao37 分钟前
【GitHub】WorldMonitor:一个工程极致主义的实时全球情报仪表盘深度解析
python·程序员·架构·github·go语言·worldmonitor·实时全球情报
其实防守也摸鱼1 小时前
GitHub开源项目破圈方法论:从技术自嗨到生态共赢
服务器·数据库·学习·开源·github·命令行·linux系统
艾斯特_1 小时前
混合检索与重排:提升召回与排序质量
后端·python·ai
网安墨雨1 小时前
MySQL数据库 SQL语句详解
自动化测试·软件测试·数据库·python·sql·mysql
柠檬味的Cat1 小时前
GEO优化系统哪家技术强
人工智能·python
爱写代码的森1 小时前
鸿蒙三方库 | harmony-utils之PasteboardUtil剪贴板数据读写详解
服务器·华为·harmonyos·鸿蒙·huawei
跨境小陈2 小时前
2026 年如何使用 Python 抓取 Reddit 数据
开发语言·网络·python
殿方雪之下2 小时前
OpenAI 兼容 API 接入实战:统一 Base URL 与用量控制
python
今天AI了吗2 小时前
Spring AI 框架实战:Java 后端集成大模型的架构设计与工程落地
java·人工智能·python·spring·机器学习
艾派森2 小时前
Web Scraper API vs 自建爬虫:一次真实对比测试,结果让人震惊
爬虫·python·网络爬虫