Python Forum
Knowledge on Python script's dependencies
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Knowledge on Python script's dependencies
#1
How can we know a Python script's dependencies recursively, entirely ie. of any kind of subroutines including of Python itself?
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the Basic Knowledge Required To Understand Python? haimen 11 6,441 Apr-30-2021, 11:54 AM
Last Post: AnupriyaSingh
  Looking for a book to deepen my Python knowledge. SpongeB0B 2 2,467 Jun-25-2020, 03:06 PM
Last Post: snippsat
  latest astroid dependencies break mypy astir13 2 2,363 Feb-28-2019, 02:14 PM
Last Post: astir13

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020