有什么简单的方法可以获取 Django 项目使用的 python 包列表?
我看过蛇食和this question , 但在 django 环境中似乎都不能很好地发挥作用。
理想情况下,我正在寻找一个我可以从 python shell 或 bash 执行的命令,以列出所有非 django 原生的 pypy 支持的依赖项。
最佳答案
这不是一个完整的答案,但希望它能成为一个明智的起点。
据我所知,django 项目的依赖项(除了 django 本身及其依赖项*
)包括:
- 您的 django 项目导入的模块
- 您的项目通过
settings.INSTALLED_APPS
(及其依赖项)加载的应用
#1 项目导入的模块
您可能可以使用 snakefood 发现这一点.
#2 通过settings.INSTALLED_APPS
加载的应用
运行以下脚本应提供 INSTALLED_APPS
中列出的应用程序的路径:
#!/usr/bin/env python
from settings import INSTALLED_APPS
from django.utils.importlib import import_module
import os
app_names = (x for x in INSTALLED_APPS if not x.startswith('django'))
app_paths = (os.path.dirname(os.path.abspath(import_module(x).__file__)) for x in app_names)
print "\n".join(x for x in app_paths if not x.startswith(os.getcwd()))
然后您可以将其传递给 snakefood
以发现它们的依赖关系。
*
为了彻底,应该可以从 settings
中发现各种后端(db/cache/auth/etc.)并将相关模块包含到您的依赖项列表。
关于python - 获取 Django 项目使用的 python 包列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8170914/