PipEnv: How to handle locally installed .whl packages

不问归期 提交于 2020-01-13 22:38:36

问题


I'm using PipEnv to set up a project, and some packages I'm needing to install from precompiled binaries. 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. What are best practices for this? Should I create a packages repository as part of the project and install from that?


回答1:


You should set up a private PyPI index server, and configure Pipenv to use that server.

Setting up a private PyPI server is trivial with a project like pypiserver:

$ mkdir private_pypi && cd mkdir 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.

Then add a [[source]] section in your projects Pipfile to points to the server (the url to use ends in /simple, so 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.

In the [packages] section, specify the index to use for those private wheels:

[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". Not adding a index="..." restriction lets Pipenv search all indexes for possible distributions.

For binary wheels published outside of an index (such as those built by Christoph Gohlke), you could consider just installing the full wheel 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.



来源:https://stackoverflow.com/questions/51528441/pipenv-how-to-handle-locally-installed-whl-packages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!