Python 应用程序目录选择

标签 python linux python-3.x directory-structure

我正在编写一个新的 Python 应用程序,打算分发给几位同事。这一次我想开阔视野,真正尝试按预期使用 Linux 目录结构(至少在某种程度上),而不是我通常无忧无虑的态度,即让所有内容都自包含并在我的主目录中的文件夹中运行。如果这不正确,您能否阅读我的分割并发表评论或提出建议。

让我们称应用程序为“narf”

/usr/narf - Install location for the actual python file(s).    
/usr/bin/narf - Either a softlink to the main python file above or use this location instead.    
/etc/narf - Any configuration files for app narf.    
/var/log/narf - Any log files for app narf.    
/usr/lib - Any required libraries for app narf.    
/run/narf - Any persistent (across reboot), but still temp files for app narf.    
/tmp/narf - Very temp files for app narf that go away with reboot

我认为我应该坚持使用/usr/X(例如/usr/bin 而不是/bin),因为我的应用程序不是系统关键的,只是一个插件。

我目前使用的是 Ubuntu 16 LTS,但其中一部分是为了尝试针对任何流行的 Linux 发行版标准化我的应用程序。

感谢您的帮助。

* 更新 *

我想我至少看到了部分问题的答案。查看/usr,我现在看到它是一个非常简单的目录,几乎类似于用户级根目录(即有 bin、lib、local、sbin 等,但仅此而已)。这让我相信我的应用程序绝对不应该存在于/usr 中,而只能存在于/usr/bin 中。

最佳答案

您最好将整个应用程序放入/opt。看这里:http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/Linux-Filesystem-Hierarchy.html#opt

然后将可执行文件的软链接(soft link)放入/usr/local/bin。看这里:https://unix.stackexchange.com/a/8658/219043

我不会担心剩下的。

关于Python 应用程序目录选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42683602/

相关文章:

linux - 使用ansible更改远程服务器上所有脚本的权限

python - 使用 subprocess.call 从 Python 中调用 awk 时出现问题

python - python中的时间和日期时间差异触发错误

python - python中的文本生成算法

python - Pandas groupby countif 与动态列

python - python中的多个返回值

linux - 从包含另一个文件中存在的关键字的文件中提取行

c - 无法创建会反转字符串的程序

python - 如何使用 tkinter 将对象放置在框架的中间?

python - Scraper 收集了很少的标题并忽略了其余的