11

I have a python module that is basically a big wrapper (which does lots more stuff besides) for an external binary (non python). I would like to include the binaries (1 binary for osx, 1 for linux) along with my code. I currently have the following in my setup.py:

package_data={'packagename': ['lib/app-osx/*', 'lib/app-linux/*', 'lib/*.awk']},

and the files are located at:

/packagename
 /lib
  script.awk
  /app-osx/
    app
  /app-linux
    app

I can't seem to find where they are installed, if they are at all? Is there a convention for this? I obviously can't use dependencies for this :(

And then, what's the best way of finding their location within the python script?

Thanks

GarethPrice
  • 1,072
  • 2
  • 14
  • 25
  • 2
    Use the [resource manager API](http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access) to access resources from your Egg. You'll probably want to use [`resource_filename`](http://peak.telecommunity.com/DevCenter/PkgResources#resource-extraction) if you need the filesystem path to your binaries. Someting like `import pkg_resources; path = pkg_resources.resource_filename('packagename', 'foo.bin')` (untested). – Lukas Graf Jul 08 '14 at 23:06
  • Thanks. Is my setup.py written correctly? – GarethPrice Jul 08 '14 at 23:14
  • From what I can tell, yes, the declaration of package resources seems to be correct. – Lukas Graf Jul 08 '14 at 23:16
  • If it doesn't work, try something like `resource_stream()` first - it should tell you exactly what in what path it was looking for the resource (`resource_filename` just builds the path, whether that resource exists or not). – Lukas Graf Jul 08 '14 at 23:20
  • There seems to be a caveat with `package_data` though, see [this answer](http://stackoverflow.com/a/14159430/1599111). – Lukas Graf Jul 08 '14 at 23:25
  • Thanks for the help, Lukas. I'm only sorry I can't accept one as the accepted answer! – GarethPrice Jul 08 '14 at 23:28
  • You're welcome, don't worry about it :) I'm just a bit too tired right now to write up a half-decent answer (setuptools stuff always takes quite a bit of time to test, and I don't like writing untested answers). Maybe I'll get around to it tomorrow. – Lukas Graf Jul 08 '14 at 23:30
  • Ah, I just realised something. My module isn't being installed as an egg, it's installing as Module.egg-info and Module/ in site-packages.. I can't use pkg_resources with non-egg installations? – GarethPrice Jul 08 '14 at 23:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56985/discussion-between-garethprice-and-lukas-graf). – GarethPrice Jul 08 '14 at 23:59
  • 1
    @GarethPrice You guys seemed to figure this out in chat. Shame that the rest of us who land on this question were abandoned, though. Care to write an answer describing your complete solution, and why each piece is necessary? You can accept it, and others can upvote. – Jonathon Reinhart May 05 '16 at 01:38
  • Sure @JonathonReinhart, I've added the solution. – GarethPrice May 07 '16 at 01:47

2 Answers2

3

With Jonathon's prompting, I went through the chat and found the solution that Lukas provided me. The solution was simply to add the following to the setup.py:

zip_safe=False
GarethPrice
  • 1,072
  • 2
  • 14
  • 25
  • 7
    Thanks! If you provide your full `setup.py`, and explain why `zip_safe=False` fixed your problem, I will happily up-vote this question and answer. – Jonathon Reinhart May 09 '16 at 21:55
1

I think MANIFEST.in can solve all problems with additional files attached to the python package.

recursive-include lib/app-osx/*
recursive-include lib/app-linux/*
recursive-include lib/*.awk
Polieter
  • 31
  • 3