如何从本地python包索引安装包?

时间:2017-08-17 21:03:27

标签: python pip pypi

https://www.python.org/dev/peps/pep-0503https://pip.pypa.io/en/stable/reference/pip_wheel/#cmdoption-i提到能够从本地目录安装python包,但它并没有明确清楚这在实践中是什么样的。

我是否在本地目录中使用相同的index.html文件? --extra-index-url的参数对于本地目录是什么样的?

3 个答案:

答案 0 :(得分:4)

如果您有想要通过pip搜索的发行版目录,则可以只包含该目录的路径:

pip install --extra-index-url=/path/to/wheelhouse somepackage

如果您根本不想搜索远程PyPI,则可以使用--index-url代替--extra-index-url。请注意,您也可以在--extra-index-url文件的顶部添加--index-url和/或requirements.txt

使用pip,您还可以直接从本地文件安装分发。  例如,要安装copyingmock发行版:

$ curl https://pypi.python.org/packages/d9/26/5ae8945356634c87cdf099bd7cee57799df46798af90ae5ccb03961c6359/copyingmock-0.1-py2.py3-none-any.whl > copyingmock-0.1-py2.py3-none-any.whl
$ pip install ./copyingmock-0.1-py2.py3-none-any.whl

我已经展示了一个二进制分发的示例,但同样适用于源代码分发(.tar.gz)。

答案 1 :(得分:2)

您不必使用任何index.html个文件。

运行以下内容应该足够了:

pip install "path/to/file.whl"

这将从本地车轮文件安装。

答案 2 :(得分:2)

我们假设您要从本地安装2个软件包:[17-Aug-2017 16:04:29 America/Chicago] [Blackouts] Current Memory Usage at beginning of script before loading Excel file: 85575176 [17-Aug-2017 16:04:32 America/Chicago] [Blackouts] Current Memory Usage after loading Excel file: 104474632 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] Current Memory Usage after parsing of Excel file is complete: 104480416 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] Current Memory Usage after PHPExcel object set to null: 104480536 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] Current Memory Usage after PHPExcel object is unset: 104480256 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] gc collected cycles: 0 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] Current Memory Usage after gc_collect_cycles: 104480416 [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] script completed: /path/to/file/Schedule Week of 14 Aug 2017 - 21 Aug 2017.xlsx [17-Aug-2017 16:04:34 America/Chicago] [Blackouts] Current Memory Usage at beginning of script before loading Excel file: 104484072 [17-Aug-2017 16:04:36 America/Chicago] [Blackouts] Current Memory Usage after loading Excel file: 122069128 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] Current Memory Usage after parsing of Excel file is complete: 122114480 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] Current Memory Usage after PHPExcel object set to null: 122114600 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] Current Memory Usage after PHPExcel object is unset: 122114320 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] gc collected cycles: 0 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] Current Memory Usage after gc_collect_cycles: 122114480 [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] script completed: /path/to/file/Schedules Week of 14 Aug 2017 - 21 Aug 2017.xlsx [17-Aug-2017 16:04:38 America/Chicago] [Blackouts] Current Memory Usage at beginning of script before loading Excel file: 122118192 [17-Aug-2017 16:04:39 America/Chicago] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted at Zend/zend_vm_execute.h:22207 (tried to allocate 72 bytes) in /mnt/nas_001_www/Classes/PHPExcel/Cell.php on line 551 abc-xyz,并且您拥有相应的软件包文件fooabc-xzy-1.2.3.tar.gz

我们将您的本地pypi目录放在foo-1.0.0.tar.gz

您的目录结构如下所示:

/my_local_pypi/simple

每个包的根/my_local_pypi/simple index.html - abc-xyz/ index.html abc-xyz-1.2.3.tar.gz - foo/ index.html foo-1.0.0.tar.gz 需要index.html个锚点条目,所以应该如下所示:

<a href></a>

然后每个$ cat /my_local_pypi/simple/index.html <!DOCTYPE html><html><body> <a href="abc-xyz">abc-xyz></a></br> <a href="foo">foo</a></br> </body></html> 需要一个指向实际包文件的$package/index.html锚点,所以它们应该如下所示:

<a href></a>

然后在$ cat /my_local_pypi/simple/abc-xyz/index.html <!DOCTYPE html><html><body> <a href="abc-xyz-1.2.3.tar.gz">abc-xyz-1.2.3.tar.gz</a></br> </body></html> $ cat /my_local_pypi/simple/foo/index.html <!DOCTYPE html><html><body> <a href="foo-1.0.0.tar.gz">foo-1.0.0.tar.gz</a></br> </body></html> 中,您可以执行以下操作:

requirements.txt

然后你应该好好去:$ cat requirements.txt --extra-index-url file:///my_local_pypi/simple/ abc-xyz==1.2.3 foo==1.0.0

另请参阅piprepo项目,该项目可以很好地生成所需的本地目录结构。