编辑
2025-04-22
Linux
00

目录

背景
操作
使用

背景

pip内部库需要内部圈子自行使用,需要搭建内部库

操作

sh
mkdir /var/docker/pypi cd /var/docker /pypi mkdir -p auth //认证文件存放目录 mkdir -p packages //pypi安装包存放目录 # 注意当前目录为/var/docker/ pip install htpasswd htpasswd -sc htpasswd.txt <username> cp ./htpasswd.txt ./auth

docker-compose.yml启动

yml
version: "3" services: pypiserver: image: pypiserver/pypiserver:latest restart: always volumes: - type: bind source: /var/docker/pypi/packages target: /data/packages - type: bind source: /var/docker/pypi/auth target: /data/auth command: -P /data/auth/htpasswd.txt -a update,download,list /data/packages ports: - "8888:8080"

启动后:

sh
(myenv) root@abc:/var/docker# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5be7a28e3637 pypiserver/pypiserver:latest "/entrypoint.sh -P /…" 55 seconds ago Up 54 seconds 0.0.0.0:8888->8080/tcp, :::8888->8080/tcp docker_pypiserver_1

访问(阿里云安全组得开放对应端口):http://www.lixf6.com:8888/simple/http://www.lixf6.com:8888

出现:(说明搭建成功)

sh
Welcome to pypiserver! This is a PyPI compatible package index serving 0 packages. To use this server with pip, run the following command: pip install --index-url http://www.lixf6.com:8888/simple/ PACKAGE [PACKAGE2...] To use this server with easy_install, run the following command: easy_install --index-url http://www.lixf6.com:8888/simple/ PACKAGE [PACKAGE2...] The complete list of all packages can be found here or via the simple index. This instance is running version 1.4.2 of the pypiserver software.

使用

1、项目sdk化

2、增加setup.py文件设置

3、MANIFEST.in文件设置

4、打包并推送到服务中

sh
# pip install twine # python setup.py check # python setup.py sdist //打包sdk,并在当前目录下生成一个dist打包文件 # twine upload --repository-url http://www.lixf6.com:8888 dist/* //把dist内的打包文件推到服务器,需要输入账号密码

5、从pypi下载并安装

sh
pip install --trusted-host www.lixf6.com:8888 --extra-index-url http://lixf6:密码@www.lixf6.com:8888 core==0.1.23 注意: 没有给服务器配置 https 的情况下,需要 --trusted-host 参数,否则 pip 会 ignore 这个仓库 如果你没有设置 Auth 的话,url 中就不需要 youruser:yourpass@ 这部分了; 如果你的 package 奇葩地和公共库中的某个包(和我们一样)重名了,你应该用 --index-url 来代替 --extra-index-url,这样它就会优先找你的包了。

本文作者:lixf6

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!