Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PipEnv: How to handle locally installed .whl packages

Tags:

python

pipenv

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?

like image 695
Brendan Avatar asked Jul 25 '18 22:07

Brendan


1 Answers

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 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 point 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.

like image 104
Martijn Pieters Avatar answered Oct 26 '22 16:10

Martijn Pieters