在共享目录上安装pip(Windows) [英] pip install on a shared directory (windows)

查看:93
本文介绍了在共享目录上安装pip(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've tried to create my own Pypi repository, respecting https://www.python.org/dev/peps/pep-0503/. My idea was to put it in a shared directory (I'm using Windows), say host1/my-pypi. I've generated the index.html needed:

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

index.html文件看起来有些正常(与pep-503中的一样).我尝试从另一台计算机上说host2,该计算机可以访问此共享目录以使用以下方式安装toto软件包:

the index.html files look somehow normal (same as in the pep-503). I try, from another computer, say host2 that has access to this shared directory to install toto package using:

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

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

but it fails (when it tries to read the file with a OSError: [Errno 22] Invalid argument: '\\\\host1\\my-pypi\\').

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

First, has anyone tried (and solved) this before? (That's the easy solution :-) ).

第二,我已经在pip代码中进行了一些挖掘,有些事情我不清楚(如果有pip的专业人士可以回答;-)).

Second, I've dug a little in the code of pip, and there are a couple of things that are unclear to me (if there's ever a pro in pip that can answer ;-) ).

  1. index.py,方法find_all_candidates:它会自动从[file://host1/my-pypi/toto]更改我的网址列表,因此似乎从未尝试读取host1\my-pypi\index.html ...很奇怪?

  1. index.py, method find_all_candidates: it automatically changes my url list from [file://host1/my-pypi/toto], so it seems that it never tries to read host1\my-pypi\index.html... weird?

index.py,方法get_page:好一点1并没有对我造成阻碍,因为它神奇地匹配了我的体系结构,但是有一个奇怪的条件:

index.py, method get_page: well point 1 is not blocking for me as it magically matches my architecture, but there's a weird condition:

# 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",
    },
)

如预期的那样,我们有:

well, as expected, we have:

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

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

but the check condition os.path.isdir(urllib_request.url2pathname(path))) is obviously false as we've discarded the network location. Hence index.html is not appended to the path (that would've been correct otherwise), and hence the error while trying to read a file that does not exist.

推荐答案

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

For a remote UNC file share, specify the file URL with four slashes:

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

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

In this case, the parsed netloc is empty and the path still includes the server hostname in UNC format, so isdir works correctly and index.html will be appended as expected.

这篇关于在共享目录上安装pip(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆