[Fixed]-Get a list of python packages used by a Django Project

7👍

This isn’t a complete answer but hopefully it’ll make a sensible starting point.

From what I can tell, the dependencies of a django project (apart from django itself and its dependencies*) consists of:

  1. Modules imported by your django project
  2. Apps loaded by your project via settings.INSTALLED_APPS (and their dependencies)

#1 Modules imported by your project

You can probably discover this using snakefood.

#2 Apps loaded via settings.INSTALLED_APPS

Running the following script should give the path to apps listed in 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()))

You can then pass this on to snakefood to discover their dependencies.


* To be thorough, it should be possible to discover the various backends (db/cache/auth/etc.) from settings and include the associated modules into your list of dependencies.

7👍

Maybe this is useful, in case the project used ‘pip’ to install the dependencies/libraries:

pip freeze

3👍

run this command inside your django project, this will write all the installed packages inside requirements.txt file

 pip freeze > requirements.txt

or if you are using python3 then use pip3 like this

pip3 freeze > requirements.txt

you will find the requirements.txt file inside your django project

2👍

pigar works fine for me.

It doesn’t cover INSTALLED_APPS yet, but that’s just a little extra work.

👤velis

Leave a comment