【问题标题】:Host Private Pip Repository托管私有 Pip 存储库
【发布时间】:2020-11-04 12:38:27
【问题描述】:

我正在尝试在 aws ec2 中托管我的私有 python 包。我为此使用烧瓶应用程序。我将包放在烧瓶应用程序根目录的文件夹中。在路由功能中,成功验证后,我尝试使用 send_file 发送文件。当我用浏览器尝试 url 时,响应是我包裹的附件。但是当我尝试使用 pip 安装时

pip install mypackage --extra-index-url=https://myurl

我收到以下错误: 找不到满足要求包名的版本(来自版本:无) 找不到匹配的分布

Pip 期望来自 url 的响应是 'text/html' 格式。最初,我收到一个错误,即响应的类型为 octset,但我更改了 mimetype。尽管不知何故我无法下载包。

另外,我尝试使用 PEP503 目录结构,

  • 简单 -包裹名字
    • index.html -index.html

在这种情况下,我的 url 应该返回什么?渲染 index.html?或链接到文件?

Ubuntu AMI 中的目录结构: 目录1

  • 包名
    • package.name-0.0.0-py3-none-any.whl
  • app.py
  • 模板
  • 静态

【问题讨论】:

    标签: python pip


    【解决方案1】:

    如果您的包裹位于 /simple/,那么您需要将其包含在您的 extra-index-url 中,例如从piwheels(第三方公共仓库)安装的命令是:

    pip install numpy --extra-index-url https://www.piwheels.org/simple
    

    你网站的/根不是pip使用的,只有简单的索引使用。 / 索引(以及除/simple/ 之外的任何内容)可以简单地用于为用户提供人类可读的信息,例如主页,甚至可能是 /project/<package>/ 项目页面(例如 https://www.piwheels.org/project/numpy/),但如果这是一个私有索引。

    您可以在没有服务器端代码的情况下运行索引,只需为每个包生成/simple/index.html/simple/<package>/index.html,将您的轮子文件存储在/simple/<package>/<filename>.whl 中:

    www
    └── simple
        ├── index.html
        ├── numpy
        │   ├── index.html
        │   └── numpy-1.19.4-cp37-cp37m-linux_armv7l.whl
        └── scipy
            ├── index.html
            └── scipy-1.5.3-cp37-cp37m-linux_armv7l.whl
    

    以及(可选)/simple/ 之外的额外页面和项目页面:

    www
    ├── about.html
    ├── index.html
    ├── project
    │   ├── index.html
    │   ├── numpy
    │   │   └── index.html
    │   └── scipy
    │       └── index.html
    └── simple
        ├── index.html
        ├── numpy
        │   ├── index.html
        │   └── numpy-1.19.4-cp37-cp37m-linux_armv7l.whl
        └── scipy
            ├── index.html
            └── scipy-1.5.3-cp37-cp37m-linux_armv7l.whl
    

    但如果你坚持使用 Flask,那很好(只要 Flask 保持运行),只要你在第一个示例中路由所有内容。

    请参阅 PyPI 和 piwheels 中的 HTML 文件以供参考,例如查看https://www.piwheels.org/simple/numpy/index.html 的源代码和(下载文件 - 不要在浏览器中打开 - 它很大)...piwheels.org/simple/index.html

    【讨论】:

    • 感谢您的解释。我的大问题是,url 函数的响应应该是什么(mydomain/simple)。我应该返回 render_template('index.html')
    • 是的。 wget 我的响应中的最终 URL 并返回该格式的 HTML 响应。
    猜你喜欢
    • 2016-04-22
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 2012-10-17
    • 2011-04-28
    相关资源
    最近更新 更多