8

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?

7
  • pip install dir/ where dir contains setup.py? Commented Jan 31, 2018 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. Commented Jan 31, 2018 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. Commented Jan 31, 2018 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. Commented Jan 31, 2018 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. Commented Jan 31, 2018 at 20:44

2 Answers 2

7

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, let me see what I can find. May I ask why you care which type of installation?
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.
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.
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/ 

2 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.