Standard location of non-code resources for python packages

This should be a common scenario, but has not yet found a suitable message.

I plan to deploy the Python library (I think the same applies to regular applications), which uses some images and other resource files. What is the standard arrangement of such items? I guess for a Foo project, the choice would be

  • You have the resources directory in the source repository, and then move the files to /usr/share/foo/
  • Put the resources directly in the python package, which is under /usr/lib/python-<version>/foo/

Any suggestions?

Edit: As suggested, it is explained that the main platform on which this will work is Linux.

+4
source share
3 answers

This question is somewhat incomplete, because the correct answer will depend on the underlying operating system, since each of them has its own modus operandi. On linux (and most UNIX-based operating systems), for example, / usr / share / foo or / usr / local / share / foo will be standard. In OS X, you can do the same, but I would think: "/ Library / Application Support / Foo" (although usually for storing settings and something else) would be a place to host such things, although if you write libraries after the Idea "Framework", all resources will be included in /Library/Frameworks/Foo.Framework "... On the other hand, applications on OS X must store all resources in the resource directory inside Foo.app

+2
source

We put the .py files in /opt/foo/foo-1.2/...

Except, of course, for static media served by Apache, which are sent to /var/www/html/foo/foo-1.1/media/...

Except, of course, for client-specific configuration files. They go to /var/opt/customer/foo/...

They follow Linux standards, as far as I understand them.

We try to stay away from the categories /usr/lib/ and /lib because they feel like part of the distribution. We lean toward /opt and /var because they are clearly separate from the directories of the Linux distribution.

+2
source

Your standard libraries are in the standard location. But it doesn't seem to me that you wrote that you want your python lib to be there. I think you should try Virtualenv .

If you don’t want to overcome all the problems (well, actually this is just sudo easy_install virtualenv for you), you can try just dumping your python library in any directory in ~/ and doing something along the lines

 import sys sys.path.append( '/full/path/to/your/lib/goes/here') 

for any application that uses your library.

Please keep in mind that the above examples are for test purposes only. For anything alive, I would recommend you use distutil . Examples of use are given here .

0
source

All Articles