Is there any easy way to get a list of python packages used by a Django project?
I've looked at snakefood and this question, but neither seem to play nicely within the django environment.
Ideally I'm looking for a command I can execute from the python shell or from bash to list all of the pypy supported dependencies that aren't native to django.
The Pip, Pipenv, Anaconda Navigator, and Conda Package Managers can all be used to list installed Python packages. You can also use the ActiveState Platform's command line interface (CLI), the State Tool to list all installed packages using a simple “state packages” command.
Download Dependencies OnlyUse the pipdeptree utility to gather a list of all dependencies, create a requirements. txt file listing all the dependencies, and then download them with the pip download command. Get the list of dependencies for a package from the setup.py file.
If you want to list all the Python packages installed in an environment, pip list command is what you are looking for. The command will return all the packages installed, along with their specific version and location. If a package is installed from a remote host (for example PyPI or Nexus) the location will be empty.
Instead, package dependencies can be seen using one of the following commands in Python: pip show: List dependencies of Python packages that have already been installed. pipdeptree: List the dependencies in a tree form. Pip list: List installed packages with various conditions.
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:
settings.INSTALLED_APPS
(and their dependencies)You can probably discover this using snakefood.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With