.. back to home

自建 pip 私有源


  1. pypiserver 下载包

https://files.pythonhosted.org/packages/34/95/6c70e2f7e8375354fd7b1db08405c93674f2e4ce4e714f379fadd06a92b1/pypiserver-2.0.1-py2.py3-none-any.whl

  1. 服务器安装
1pip install pypiserver-2.0.1-py2.py3-none-any.whl 
  1. 准备一个存放位置 ~/pypiserver/packages/

  2. 手工启动

1pypi-server run -p 9000 ./packages/

访问 http://127.0.0.1:9000/ 即可

pip安装时引用:

1pip install --index-url http://127.0.0.1:9000/simple/ 
  1. 服务配置(可选)
 1# /etc/systemd/system/pypi_server.service
 2[Unit]
 3Description=A minimal PyPI server for use with pip/easy_install.
 4After=network.target
 5
 6[Service]
 7Type=simple
 8# systemd requires absolute path here too.
 9PIDFile=/var/run/pypiserver.pid
10User=www-data
11Group=www-data
12# 启动命令&日志文件存放位置
13ExecStart=/usr/local/bin/pypi-server -p 9090 -a update,download --log-file /var/log/pypiserver.log /root/home/packges
14ExecStop=/bin/kill -TERM $MAINPID
15ExecReload=/bin/kill -HUP $MAINPID
16Restart=always
17# 模块存放地址
18WorkingDirectory=/root/home/packages
19
20TimeoutStartSec=3
21RestartSec=5
22
23[Install]
24WantedBy=multi-user.target

启动脚本

1systemctl enable pypi_server
2
3# 后期维护
4$ systemctl status pypi_server    # 查看进程状态
5$ systemctl stop pypi_server    # 终止 pypi_server 进程
6$ systemctl start pypi_server    # 启动 pypi_server 进程
7$ systemctl restart pypi_server    # 重新启动 pypi_server 进程
  1. 下载包 注意版本的话需要自己另外下载
1pip list --format=freeze > re.txt
2# cat re.txt 
3pip download -r ./re.txt -d .