5

使用devpi搭建本地源 - 夜雨秋灯录

 2 years ago
source link: https://privaterookie.github.io/posts/2019-04-17-%E4%BD%BF%E7%94%A8devpi%E6%90%AD%E5%BB%BA%E6%9C%AC%E5%9C%B0%E6%BA%90.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用 devpi 搭建本地 pypi 源


可以使用 docker 快速部署一个 Python 本地镜像源

# 设置 devpi 服务器管理员密码
DEVPI_PASSWORD = 123

mkdir -p /src/docker/devpi
mkdir /tmp/wheelhouse

docker run -d --name devpi \
    --publish 3141:3141 \
    --volume /tmp/wheelhouse:/wheelhouse
    --volume /srv/docker/devpi:/data \
    --env=DEVPI_PASSWORD=$DEVPI_PASSWORD \
    --restart always \
    muccg/docker-devpi

接着先在本地下载好所需的wheel包,requirements.txt文件内容即为我们需要的 Python 库列表

pip wheel --wheel-dir /tmp/wheelhouse -r requirements.txt

如果从 pip 源下载的库已经是 wheel 包的话文件将会被直接放在 /tmp/wheelhouse 内,如果是 tar 包,pip 会先 build 出 wheel 包,这可能需要一些时间。下载完成后 wheelhouse 内容类似 于

ll /tmp/wheelhouse
total 524K
-rwxrwxrwx 1 rookie rookie 155K Apr  6 23:40 certifi-2019.3.9-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 131K Apr  6 23:40 chardet-3.0.4-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie  58K Apr  6 23:40 idna-2.8-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie  57K Apr  6 23:40 requests-2.21.0-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 116K Apr  6 23:40 urllib3-1.24.1-py2.py3-none-any.whl

下载完成后如果本地环境安装了devpi客户端,可以直接上传 wheel 包,不过由于我们在创建容器时已经 把 wheelhouse 文件夹挂载进去,也可以在在容器里直接操作

# 进入容器
docker exec -it -u root devpi bash

# 登陆并上传
devpi use http://<host_ip>:3141/root/public --set-cfg
devpi login root 123
devpi upload --from-dir /wheelhouse

上传完成后可以使用 http://<host_ip>:3141 查看 pip 本地源服务器状态。 若要临时使用可以使用 pip install 的 --index--trust-host 选项

pip install --index http://<host_ip>:3141/root/public/+simple/ \
            --trusted-host <host_ip>

或者修改 pip.conf 文件永久使用

# vim ~/.pip/pip.conf
[global]
index_url = http://<host_ip>:3141/root/public/+simple/
trusted-host = <host_ip>
[search]
index = http://<host_ip>:3141/root/public/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK