Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a wheel/egg and all dependencies for a python project

In order to stage python project within our corporation I need to make an installable distribution.

This should include:

  • An egg or whl for my project
  • An egg or whl for every dependency of the project
  • (optionally) produce a requirements.txt file listing all the installable components for this release

Is there an easy plug in, (e.g. an alternative to bdist_wheel) that will not only compile one wheel but also that project's components?

Obviously I can script this, but I was hoping that there might be a short-cut that builds the package + dependencies in fewer steps.

This needs to work on Python 2.7 on Windows + Linux.

like image 487
Salim Fadhley Avatar asked Sep 26 '14 12:09

Salim Fadhley


People also ask

How do you build your project into a wheel in Python?

Go to your command prompt/ conda prompt from where you can run python and pip commands, if not sure then check this link. Change directory in the command prompt and navigate to your project root directory where setup.py is placed . Execute python setup.py bdist_wheel . Voila!

Does a Python wheel include dependencies?

Python package installed with pip , e.g. WheelPython dependencies can be specified as dependencies in your packaging, and automatically installed by pip . You can include third party C libraries in wheels, but for sufficiently complex dependencies that won't work.

How do I get all dependencies of a python package?

Use the pipdeptree utility to gather a list of all dependencies, create a requirements. txt file listing all the dependencies, and then download them with the pip download command. Get the list of dependencies for a package from the setup.py file.


2 Answers

With the latest pip and wheel, you can simply run

pip wheel . 

within your project folder, even if your application isn't on PyPi. All wheels will be stored in the current directory (.).

To change the output directory (to for example, ./wheels), you may use the -w / --wheel-dir option:

pip wheel . -w wheels 

All the options available are listed at the pip documentation.

like image 24
jtpereyda Avatar answered Sep 22 '22 03:09

jtpereyda


You will need to create a setup.py file for your package. Make sure you have the latest setuptools and pip installed. Then run the following:

python setup.py bdist_wheel 

This will create a wheel file for your package. This assumes you don't have C/C++ headers, DLLs, etc. If you do, then you'll probably have a lot more work to do.

To get dependencies, you will want to create a requirements.txt file and run the following:

pip wheel -r requirements.txt 

If your package isn't on PyPI, then you'll have to manually copy your package's wheel file into the wheel folder that this command creates. For more information see the following excellent article:

  • http://lucumr.pocoo.org/2014/1/27/python-on-wheels/
like image 83
Mike Driscoll Avatar answered Sep 22 '22 03:09

Mike Driscoll