Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build Python project including dependencies?

I have a few projects, all containing setup.py and requirements.txt. Is it possible to package a whole project in one single file including all requirements compiled and ready to install?

What I have tried:

python setup.py bdist_wheel

Builds a .whl file and puts it in the dist directory. The wheel does not contain any dependencies.

pip wheel -r requirements.txt -w wheelhouse

Builds wheels for every single requirement and puts it in the wheelhouse directory. Includes nicely compiled code for numpy for example (I know I have to build this on every platform I want it to run later on, that's fine).

Seems I am just missing the last piece of the puzzle.

like image 858
kev Avatar asked Jun 03 '16 05:06

kev


People also ask

How do you add dependencies to a Python project?

Installing Python dependencies The recommended way to install Python library dependencies is with the pip command when a virtualenv is activated. Pip and virtualenv work together and have complementary responsibilities. Pip downloads and installs application dependencies from the central PyPi repository.

How do I package a Python script with all dependencies?

Install_requires Example install_requires is a section within the setup.py file in which you need to input a list of the minimum dependencies needed for a project to run correctly on the target operating system (such as ubuntu). When pip runs setup.py, it will install all of the dependencies listed in install_requires.

How does Python project manage dependencies?

Using venv and pipenv are two methods of managing dependencies in Python. They are simple to implement and, for most users, adequate solutions for handling multiple projects with different dependencies. However, they are not the only solutions. Other services can complement their use.


1 Answers

You probably want to take a look at tools like cx_Freeze or PyInstaller if you absolutely want one single file containing everything. Pip itself cannot do what you want.

like image 175
renefritze Avatar answered Sep 18 '22 16:09

renefritze