【问题标题】:pip install on a shared directory (windows)pip 安装在共享目录上(Windows)
【发布时间】:2017-07-10 15:04:48
【问题描述】:

我尝试创建自己的 Pypi 存储库,尊重 https://www.python.org/dev/peps/pep-0503/。我的想法是把它放在一个共享目录中(我使用的是 Windows),比如host1/my-pypi。我已经生成了所需的 index.html:

(dir) host1\my-pypi
     -> (dir) toto
         (file) index.html
         (file) toto-1.0.0.whl
     -> (file) index.html

index.html 文件看起来很正常(与 pep-503 中的相同)。我尝试从另一台计算机上说host2,它有权访问此共享目录以安装 toto 包:

pip install --index-url file://host1/my-pipy toto

但它失败了(当它尝试使用OSError: [Errno 22] Invalid argument: '\\\\host1\\my-pypi\\' 读取文件时)。

首先,有没有人尝试过(并解决过)这个问题?(这是简单的解决方案 :-))。

其次,我在 pip 的代码中挖掘了一些东西,有几件事我不清楚(如果 pip 中的专业人士可以回答 ;-))。

  1. index.py,方法find_all_candidates:它会自动将我的url列表从[file://host1/my-pypi/toto]更改,所以它似乎从不尝试读取host1\my-pypi\index.html...奇怪吗?

  2. index.py, 方法get_page:好吧,第 1 点对我来说并没有阻塞,因为它神奇地匹配了我的架构,但是有一个奇怪的情况:

    # Tack index.html onto file:// URLs that point to directories
    (scheme, netloc, path, params, query, fragment) = \
        urllib_parse.urlparse(url)
    if (scheme == 'file' and
            os.path.isdir(urllib_request.url2pathname(path))):
        # add trailing slash if not present so urljoin doesn't trim
        # final segment
        if not url.endswith('/'):
            url += '/'
        url = urllib_parse.urljoin(url, 'index.html')
        logger.debug(' file: URL is directory, getting %s', url)
    resp = session.get(
        url,
        headers={
            "Accept": "text/html",
            "Cache-Control": "max-age=600",
        },
    )
    

    好吧,正如预期的那样,我们有:

    scheme = 'file'
    netloc = 'host1'
    path = '/my-pypi/'
    

    但是检查条件os.path.isdir(urllib_request.url2pathname(path))) 显然是错误的,因为我们已经丢弃了网络位置。因此index.html 没有附加到路径中(否则会是正确的),因此在尝试读取不存在的文件时会出错。

【问题讨论】:

  • 打开了一个问题:github.com/pypa/pip/issues/4615
  • 我一直在尝试做类似的事情。设置本地 UNC 路径小 pip 存储库。我从 resolvers.py (pip 方法)中得到错误我想知道您是否有一些您使用的 index.html 文件的示例?如果映射驱动器(我什至无法让它工作),似乎你可以让它工作我刚刚去了这里:pypi.org/simple 并“下载”了 index.html 全局文件和每个包的 index.html。我从 href HTML 属性中删除了网址,并使用了相对路径。非常感谢任何帮助!

标签: python python-3.x pip


【解决方案1】:

对于远程 UNC 文件共享,使用四个斜杠指定文件 URL:

pip install --index-url file:////host1/my-pypi toto

在这种情况下,解析后的 netloc 为空,path 仍包含 UNC 格式的服务器主机名,因此 isdir 工作正常,index.html 将按预期附加。

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2011-02-10
    • 2013-11-07
    • 2021-01-29
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多