Python Forum

Full Version: Knowledge on Python script's dependencies
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can we know a Python script's dependencies recursively, entirely ie. of any kind of subroutines including of Python itself?
you can get this from https://pypi.org/pypi/package/json (replace module with actual package name)
then use index ["info"]["requires_dist"] from your python script
or simply open url and search for "requires_dist"
you can also find required python version with ["info"]["requires_python"] or search "requires_python"

Edit 10:46 PM EDT
Here's a quick module that will get the info
import requests
import json
from pathlib import Path
import sys


def get_dependencies(package_name):
    pkginfo = {}

    url = f"https://pypi.org/pypi/{package_name}/json"
    response = requests.get(url)
    if response.status_code == 200:
        pkginfo = json.loads(response.content)
    else:
        print(f"Unable to fetch url: {url}")
        sys.exit(-1)
    print(f"\nOther packages: {pkginfo['info']['requires_dist']}")
    print(f"python versions: {pkginfo['info']['requires_python']}")


def main():
    get_dependencies('pyflowchart')

if __name__ == '__main__':
    main()
results:
Output:
Other packages: ['astunparse', 'chardet'] python versions: >=3.6
To get the full list, follow the tree as each dependency may also have it's own dependencies.