7

Is there a way, using setup.py, to install a python package as a wheel/pip-style package (i.e. dist-info) instead of the egg installation that setup.py does by default (i.e. egg-info)?

For example, if I have a python package with a setup.py script and I run the following command, it will install the package as an egg.

> python setup.py install

However, I can build a wheel first, and then use pip to install that wheel as a wheel/dist-info type installation

> python setup.py bdist_wheel
> pip install ./dist/package-0.1-py2-none-any.whl

Is there a way to install the package as a wheel/dist-info installation directly from setup.py? Or is the two-step process using both setuptools and pip necessary?

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
  • `pip install dir/` where `dir` contains `setup.py`? – hoefling Jan 31 '18 at 20:19
  • @hoefling `pip` will install from a directory containing a `setup.py`, but it just calls `setup.py install`, so it generates the same egg install. – Brendan Abel Jan 31 '18 at 20:25
  • That's not true. Try it out and you will see that when installing from a directory, `pip` will run the `bdist_wheel` command, then install the package from the built wheel file. At least this is the behaviour I observe with current `pip 9.0.1`. – hoefling Jan 31 '18 at 20:41
  • @hoefling Yes, I've tried it. `pip` will absolutely create an egg and install it. I don't believe `pip` will install *from* an egg binary distribution file, since the egg format doesn't contain enough metadata to know if that particular bdist will work for that specific python installation. Which is part of the reason the wheel format was created. – Brendan Abel Jan 31 '18 at 20:42
  • @hoefling hmmm... I also have a `pip 9.0.1` and it's behaving differently for me. I'm on windows if that matters. – Brendan Abel Jan 31 '18 at 20:44
  • I can only get the `.egg-info` install using pip 9.0.1 on Linux. – wim Jan 31 '18 at 20:48
  • Sorry for the misleading, my bad! Turns out that I indeed used `pip` built from `pypa/pip` repository and not the released one. – hoefling Jan 31 '18 at 21:38

2 Answers2

6

Update: Confirmed, this has landed in pip now. If you are still seeing .egg-info installs when pip installing from a directory, then just upgrade your pip installation. Note that --editable installs will still use egg-info.


Original answer below:

This feature is coming soon. This was issue #4611. Follow the trail and you will find PR 4764 to pip, merged into master approx a week ago. In the meantime, you can

pip wheel . 
pip install ./mypackage.whl
wim
  • 338,267
  • 99
  • 616
  • 750
  • Hmm, let me see what I can find. May I ask why you care which type of installation? – wim Jan 31 '18 at 20:30
  • 1
    I prefer the flat install that wheel-style installations use, and they're the favored installation method, as eggs are deprecated. I know I can modify the setup.py scripts to use `zip_safe=False` to get a flat structure, but I'd rather not have to modify a package file for what is really a local installation configuration option. – Brendan Abel Jan 31 '18 at 20:36
  • I have the same problem, with pip 21.0.1, where it doesn't work with a namespace package. Only if I do the two steps. – Roelant Mar 23 '21 at 14:40
0

For me the proposed solution still didn't work (even with pip 21.0.1), and due to versioning (package-name-XX.YY), I also didn't know the name of the .whl file. You can tell pip to look in the directory and take the .whl from there:

python setup.py bdist_wheel
pip install package-name --find-links dist/
Roelant
  • 4,508
  • 1
  • 32
  • 62
  • If you have a recent version of `pip`, you should be able to just do `pip install .` now, without having to create a .whl first. – Brendan Abel Mar 23 '21 at 23:15
  • I tried that, and I did check that I have the latest version of pip... It was clashing with an already existing namespace package, not sure if that was the reason. – Roelant Mar 24 '21 at 08:20