python 包的标准非代码资源位置

发布于 2024-07-18 18:26:27 字数 387 浏览 7 评论 0原文

这应该是一个常见的场景,但还找不到任何相关的帖子。

我计划部署一个 Python 库(我想这同样适用于常规应用程序),它使用一些图像和其他资源文件。 此类物品的标准位置是什么? 我想,对于项目 Foo ,选择将是

  • 在源存储库中拥有 resources 目录,然后将文件移动到 /usr/share/foo/
  • 将资源直接放在 /usr/lib/python-/foo/ 下的 python 包中 有

什么建议吗?

编辑:按照建议,澄清将运行的主要平台是 Linux。

This should be a common scenario, but could not find any relevant post yet..

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

  • Have resources directory in the source repository and then move files to /usr/share/foo/
  • Place resources directly inside the python package that goes under /usr/lib/python-<version>/foo/

Any suggestions?

Edit: As suggested, clarifying that the main platform this will be running on is Linux.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残月升风 2024-07-25 18:26:27

这个问题有点不完整,因为正确的答案取决于底层操作系统,因为每个操作系统都有自己的操作方式。 在 Linux(以及大多数基于 UNIX 的操作系统)中,例如 /usr/share/foo 或 /usr/local/share/foo 将是标准。 在 OS X 中你可以做同样的事情,但我认为“/Library/Application Support/Foo”(尽管这通常用于存储设置和诸如此类的东西)将是放置这些东西的地方,尽管如果你正在编写遵循以下内容的库“框架”的想法,所有资源都将包含在 /Library/Frameworks/Foo.Framework 中”...另一方面,OS X 上的应用程序应将所有资源保留在 Foo.app 内的 Resources 目录中

This question is somewhat incomplete, because a proper answer would depend on the underlying operating system, as each has its own modus operandi. In linux (and most unix based OSs) for example /usr/share/foo or /usr/local/share/foo would be the standard. In OS X you can do the same, but I would think "/Library/Application Support/Foo" (although that's usually for storing settings and whatnot) would be the place to put such things, though if you're writing libraries following the "Framework" idea, all the resources would be included in the /Library/Frameworks/Foo.Framework" ... Apps on OS X on the other hand should keeps all there resources within the Resources directory inside Foo.app

等风也等你 2024-07-25 18:26:27

我们将非 .py 文件放入 /opt/foo/foo-1.2/...

当然,对于 Apache 提供的静态媒体除外,该文件位于 /var/www /html/foo/foo-1.1/media/...

当然,客户特定的配置文件除外。 他们去了
/var/opt/customer/foo/...

这些遵循我所理解的 Linux 标准。

我们尝试远离 /usr/lib//lib 类型的位置,因为这些位置感觉像是发行版的一部分。 我们倾向于 /opt/var 因为它们与 Linux 发行版目录明显分开。

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

Except, of course, for static media that is served by Apache, that goes to /var/www/html/foo/foo-1.1/media/...

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

Those follow the Linux standards as I understand them.

We try to stay away from /usr/lib/ and /lib kinds of locations because those feel like they're part of the distribution. We lean toward /opt and /var because they're clearly separated from the linux distro directories.

醉殇 2024-07-25 18:26:27

标准位置是标准库所在的位置。 但从你所写的内容来看,我听起来并不认为你会想要你的 python 库在那里。 我认为你应该尝试 Virtualenv

如果你不想经历所有的麻烦(好吧,这对你来说实际上只是 sudo easy_install virtualenv ),你可以尝试将你的 python 库转储到你的任何目录中>~/ 并对

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

使用您的库的任何给定应用程序执行一些操作。

请记住,给出的示例仅用于测试目的。 对于任何实时的内容,我建议您使用 distutil此处给出了使用示例。

The standard location is where your standard libs goes. But it doesn't sound to me from what you've written, that you'll want your python lib there. I think you should try out Virtualenv.

If you don't want to go through all the trouble (well, it really just amounts to sudo easy_install virtualenv for you), you could try to just dump your python lib in any dir in your ~/ and do something along the lines of

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

to any given application that uses your lib.

Please bear in mind, that the examples given are for test-purposes only. For anything live-ish, I would recommend that you use distutil. Examples of use are given here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文