0

if I have an application that is written part in Python and has dependencies like numpy and scipy and part in C, how can I package it as an executable (e.g. for Linux) or as a source distribution in a way that does not depend on installing numpy/scipy and other Python modules? ie is it possible to package numpy/scipy into a binary? thanks.

  • 1
    [Distutils](http://docs.python.org/distutils/index.html#distutils-index) can package C extension files with your Python application. The easiest way to resolve dependencies on your user's computer is to use a package manager, or give clear instructions in the user guide. You don't really want to be building a whole new Python distribution. – Benjamin Hodgson Oct 01 '12 at 13:01
  • But what if you want to make a binary? –  Oct 02 '12 at 12:31
  • Built distributions are explained in the [official Distutils documentation](http://docs.python.org/distutils/builtdist.html). My advice is not to go to the effort of trying to repackage numpy into your installer. Instead, try to document the dependencies carefully (with installation instructions for each dependency, if you like) and let the user set up their own environment. – Benjamin Hodgson Oct 02 '12 at 14:08
  • @poorsod That's a terrible idea for software targeted at end users. – millimoose Oct 02 '12 at 23:49
  • This is assuming your "main" executable is a Python one; that is, that you're *extending* Python, not *embedding* it. Generally, if you want a user-friendly solution, it's best to do it in a platform-dependent way. On Windows and OS X, you'd use [`py2exe`](http://www.py2exe.org/) and [`py2app`](respectively), both of which can bundle binary and script dependencies with or in your app. For Loonixen, you should make a distribution-appropriate package (e.g. a `.deb`) that points to the needed dependencies in the package repositories; installing your C components as a site-wide Python extension. – millimoose Oct 02 '12 at 23:57

1 Answers1

1

If you want a standalone executable, I suggest trying PyInstaller. It is cross-platform (Windows, Linux, MacOS X, ...) and has quite extensive support out-of-the-box for many packages with binary dependencies, including numpy.

Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
  • Are there alternatives to it? Does it have limitations if you include a package that it doesn't have out of the box support for? –  Oct 07 '12 at 23:37
  • I've been using it for a quite complex application on Windows (planning on extending it to package for Mac OS X and Linux), and it works very well. I suggest you try to follow the instructions provided and I'll be able to help if you hit any snags. The alternatives are [py2exe](http://www.py2exe.org/) for Windows (and [py2app](http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html) for Mac OS X) as @millimoose has mentioned in your question's comments, and [cx_Freeze](http://cx-freeze.sourceforge.net/) which is also cross-platform. – Pedro Romano Oct 08 '12 at 07:40