{"record":{"id":"93e97d9611a6c162","repo":"OpenBB-finance/OpenBB","slug":"missing-required-package-missing-package-pleas","errorCode":null,"errorMessage":"Missing required package: {missing_package}. Please install dependencies: pip install pycountry beautifulsoup4 requests","messagePattern":"Missing required package: (.+?)\\. Please install dependencies: pip install pycountry beautifulsoup4 requests","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"openbb_platform/core/openbb_core/provider/utils/update_country_data.py","lineNumber":37,"sourceCode":"\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport json\nimport re\nimport unicodedata\nfrom datetime import date\nfrom pathlib import Path\n\nimport requests\n\ntry:\n    import pycountry\n    from bs4 import BeautifulSoup\nexcept ImportError as e:\n    missing_package = str(e).split(\"'\")[1] if \"'\" in str(e) else \"unknown\"\n    raise ImportError(\n        f\"Missing required package: {missing_package}. \"\n        \"Please install dependencies: pip install pycountry beautifulsoup4 requests\"\n    ) from e\n\nSCRIPT_DIR = Path(__file__).parent\nDEFAULT_OUTPUT = SCRIPT_DIR / \"country_data.json\"\n\nHEADERS = {\n    \"User-Agent\": (\n        \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \"\n        \"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\"\n    )\n}\n\n# Expected member counts for sanity checks (approximate — update when membership changes)\nEXPECTED_COUNTS: dict[str, int | tuple[int, int]] = {\n    \"G7\": 7,\n    \"G20\": 20,  # 19 countries + EU (we only count countries)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/core/openbb_core/provider/utils/update_country_data.py#L19-L55","documentation":"An ImportError raised at import time of openbb_core/provider/utils/update_country_data.py, a maintenance script that scrapes country data with requests + BeautifulSoup and pycountry. If either pycountry or beautifulsoup4 is missing, the except ImportError block extracts the offending package name and re-raises with install instructions. It fails before any code in the module can run.","triggerScenarios":"Importing update_country_data (directly or via tooling that scans all modules) in an environment where 'pip install pycountry beautifulsoup4 requests' has not been run - e.g. a minimal install of openbb-core without the scraping extras, or a CI venv pruning optional dependencies.","commonSituations":"Running the country-data refresh script on a fresh machine; CI environments that only install core requirements; dependency conflicts where pip uninstalled bs4/pycountry during a resolve.","solutions":["Install the extras: pip install pycountry beautifulsoup4 requests.","If it was pulled in by a module scan (e.g. pytest collection), either install the deps or exclude the script from collection.","For library consumers: don't import this module; it is a data-generation utility, not runtime API - guard imports behind a try/except or optional extra.","After installing, verify with python -c 'import pycountry, bs4'."],"exampleFix":"# before\nfrom openbb_core.provider.utils.update_country_data import update_country_data  # ImportError\n\n# after (install first: pip install pycountry beautifulsoup4 requests)\nfrom openbb_core.provider.utils.update_country_data import update_country_data","handlingStrategy":"try-catch","validationCode":"import importlib.util\nfor pkg in ('pycountry', 'bs4', 'requests'):\n    if importlib.util.find_spec(pkg) is None:\n        raise ImportError(f'install {pkg} first: pip install pycountry beautifulsoup4 requests')","typeGuard":"def can_import_update_country_data() -> bool:\n    import importlib.util\n    return all(importlib.util.find_spec(p) for p in ('pycountry', 'bs4', 'requests'))","tryCatchPattern":"try:\n    from openbb_core.provider.utils.update_country_data import update_country_data\nexcept ImportError as e:\n    if 'Missing required package' in str(e):\n        subprocess.run([sys.executable, '-m', 'pip', 'install', 'pycountry', 'beautifulsoup4', 'requests'], check=True)\n        from openbb_core.provider.utils.update_country_data import update_country_data","preventionTips":["Install the scraping extras in environments that run data-refresh scripts.","Never import maintenance scripts from library code; keep them behind optional extras."],"tags":["python","dependencies","import-error","openbb"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}