简体   繁体   English

PipEnv:如何处理本地安装的 .whl 包

[英]PipEnv: How to handle locally installed .whl packages

I'm using PipEnv to set up a project, and some packages I'm needing to install from precompiled binaries.我正在使用 PipEnv 来设置一个项目,我需要从预编译的二进制文件中安装一些包。 In a previous project I just pipenv installed the .whl files from some local folder into my environment, but this seems to cause issues with the lock file throwing an error if someone else tries to install from the repository since the pipfile tracks the local path.在以前的项目中,我只是 pipenv 将 .whl 文件从某个本地文件夹安装到我的环境中,但这似乎会导致锁定文件的问题,如果其他人尝试从存储库安装,则会引发错误,因为 pipfile 跟踪本地路径。 What are best practices for this?这方面的最佳做法是什么? Should I create a packages repository as part of the project and install from that?我应该创建一个包存储库作为项目的一部分并从中安装吗?

You should set up a private PyPI index server, and configure Pipenv to use that server .您应该设置一个私有 PyPI 索引服务器,并配置 Pipenv 以使用该服务器

Setting up a private PyPI server is trivial with a project like pypiserver :使用像pypiserver这样的项目来设置私有 PyPI 服务器是微不足道的:

$ mkdir private_pypi && cd private_pypi
$ pipenv install   # create pipenv files
$ pipenv install pypiserver
$ mkdir packages
$ pipenv run pypi-server -p 8080 ./packages &

and put your wheels into their projectname subdirectry of the packages directory, or use twine to publish your package to the server.并将您的轮子放入packages目录的projectname子目录中,或者使用twine将您的包发布到服务器。

Then add a [[source]] section in your projects Pipfile to point to the server (the url to use ends in /simple , so http://hostname:8080/simple ):然后在您的项目Pipfile添加一个[[source]]部分以指向服务器(要使用的 url 以/simple结尾,因此http://hostname:8080/simple ):

[[source]]
url = "http://hostname:8080/simple"
verify_ssl = false
name = "some_logical_name"

You can use the default name = "pypi" section as a guide.您可以使用默认name = "pypi"部分作为指导。

In the [packages] section, specify the index to use for those private wheels:[packages]部分,指定用于这些私有轮子的索引:

[packages]
wheel1 = {version="*", index="some_logical_name"}
wheel2 = {version="0.41.1", index="some_logical_name"}
some_public_project = "*"

Again, you can explicitly name any of the named indices, including index="pypi" .同样,您可以显式命名任何命名索引,包括index="pypi" Not adding a index="..." restriction lets Pipenv search all indexes for possible distributions.不添加index="..."限制让Pipenv搜索所有索引以寻找可能的分布。

For binary wheels published outside of an index (such as those built by Christoph Gohlke ), you could consider just installing the full wheel URL:对于在索引之外发布的二进制轮子(例如由 Christoph Gohlke 构建的轮子),您可以考虑只安装完整的轮子 URL:

pipenv install https://download.lfd.uci.edu/pythonlibs/l8ulg3xw/aiohttp-3.3.2-cp36-cp36m-win_amd64.whl

This does force everyone using your Pipfile to a specific platform.这确实迫使每个人使用您的 Pipfile 到特定平台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM