YouTip LogoYouTip

Skills Dependencies

Skill scripts often require third-party libraries. How to declare, install, and lock these dependencies is the foundation for ensuring reliable Skill execution.\\\\n\\\\n* * *\\\\n\\\\n## Dependency Declaration File\\\\n\\\\nCreate requirements.txt (Python) or package.json (Node.js) in the Skill's scripts/ directory to centrally declare all dependencies.\\\\n\\\\n### Python Dependency: requirements.txt\\\\n\\\\n```python\\\\n# File path: scripts/requirements.txt\\\\n# Format: package name==Version number (lock version to ensure reproducible installation)\\\\npandas==2.1.4 # Data Handle.\\\\nopenpyxl==3.1.2 # Excel Read/Write\\\\npypdf==3.17.0 # PDF Handle.\\\\npython-docx==1.1.0 # Word Document Handle.\\\\nrequests==2.31.0 # HTTP Request\\\\n\\\\n### Node.js Dependency: package.json\\\\n\\\\n## Example\\\\n\\\\n```json\\\\n{\\\\n"name":"my-skill-scripts",\\\\n"version":"1.0.0",\\\\n"description":"Skill Script Node.js Dependencies",\\\\n"dependencies":{\\\\n"xlsx":"^0.18.5",\\\\n"puppeteer":"^21.0.0"\\\\n}\\\\n}\\\\n\\\\n* * *\\\\n\\\\n## Describe Installation Method in SKILL.md\\\\n\\\\n## Dependency Installation\\\\n\\\\nBefore first use, run the following command to install Python dependencies:\\\\n\\\\n```bash\\\\npip install -r scripts/requirements.txt --break-system-packages\\\\n\\\\nIf the runtime environment already has dependencies pre-installed, you can skip this step.\\\\n\\\\n* * *\\\\n\\\\n## Auto-install Dependencies in Scripts\\\\n\\\\nFor Skills that need zero-configuration execution, you can add dependency self-checking and automatic installation logic at the beginning of the script.\\\\n\\\\n## Example\\\\n\\\\n```python\\\\n# File path: scripts/auto_deps.py\\\\n\\\\nimport subprocess\\\\nimport sys\\\\nimport importlib\\\\n\\\\n# Define dependency list: (pip install name, importName, Version Requirements)\\\\n DEPENDENCIES =[\\\\n("pandas","pandas",">=2.0"),\\\\n("openpyxl","openpyxl",">=3.0"),\\\\n("python-docx","docx",None),# NoneVersion Requirements\\\\n]\\\\n\\\\ndef install_if_missing(pip_name: str, import_name: str) ->bool:\\\\n """Check and install dependency packages as needed"""\\\\ntry:\\\\n importlib.import_module(import_name)\\\\nreturn True# Already installed, returning directly\\\\nexcept ImportError:\\\\nprint(f"NormalinInstall:{pip_name}...")\\\\n result =subprocess.run(\\\\n[sys.executable,"-m","pip","install", pip_name,\\\\n"--break-system-packages","--quiet"],\\\\n capture_output=True, text=True\\\\n)\\\\nif result.returncode==0:\\\\nprint(f"Installation successful:{pip_name}")\\\\nreturn True\\\\nprint(f"Installation failed:{pip_name}n{result.stderr}")\\\\nreturn False\\\\n\\\\ndef ensure_all_deps() ->bool:\\\\n """Ensure all Dependencies are installed"""\\\\n failed =[]\\\\nfor pip_name, import_name, _ in DEPENDENCIES:\\\\nif not install_if_missing(pip_name, import_name):\\\\n failed.append(pip_name)\\\\nif failed:\\\\nprint(f"The following Dependencies installation failed:{', '.join(failed)}")\\\\nreturn False\\\\nreturn True\\\\n\\\\nif __name__ =="__main__":\\\\nif not ensure_all_deps():\\\\nsys.exit(1)\\\\n\\\\n# DependenciesAfter ready, Normal executes logic normally\\\\nimport pandas as pd\\\\nprint("All dependencies are ready, starting execution...")\\\\n\\\\nOutput:\\\\n\\\\nNormalinInstall: python-docx...\\\\nInstallation successful:python-docx\\\\nAll dependencies are ready, starting execution...\\\\n\\\\n* * *\\\\n\\\\n## Version Conflict Handling Strategies\\\\n\\\\nWhen Skill dependencies conflict with system package versions, there are several handling approaches:\\\\n\\\\n| Strategy | Approach | Applicable Scenario |\\\\n| --- | --- | --- |\\\\n| Loose Version Requirements | Use >= instead of ==, allowing higher versions | Most scenarios, good compatibility |\\\\n| Virtual Environment | Install in venv, isolated from system | Strict version requirements |\\\\n| Use System's Existing Version | Don't lock version, use system's installed version | Dependencies are common libraries with small version impact |\\\\n\\\\n### Creating a Virtual Environment (Optional)\\\\n\\\\n## Example\\\\n\\\\n```bash\\\\n# in Skill Create a virtual environment in the directory\\\\n python3 -m venv scripts/.venv\\\\n\\\\n# Activate virtual environment\\\\nsource scripts/.venv/bin/activate\\\\n\\\\n# inInstall Dependencies in the virtual environment\\\\n pip install-r scripts/requirements.txt\\\\n\\\\n# inRun the script in the virtual environment\\\\n python scripts/process.py\\\\n\\\\n> In Claude's execution environment, virtual environments are usually not needed because each session is relatively isolated. Virtual environments are mainly used during local development to avoid conflicts with other projects on the development machine.\\\\n\\\\n* * *\\\\n\\\\n## Dependency Documentation Standards\\\\n\\\\nIn SKILL.md or a separate README, all external dependencies should be clearly listed to help users understand requirements before installation.\\\\n\\\\n## System Requirements\\\\n\\\\n### Runtime Environment\\\\n- Python 3.8 or higher\\\\n- pip (Python package management tool)\\\\n\\\\n### Python Dependencies\\\\n\\\\n| Package | Version | Purpose |\\\\n|---------|---------|---------|\\\\n| pandas | >=2.0 | Data reading and processing |\\\\n| openpyxl | >=3.0 | Excel file reading and writing |\\\\n| python-docx | any | Word document generation |\\\\n\\\\n### System Tools (Optional)\\\\n- pandoc: Format conversion (apt-get install pandoc)
← Vue3 Blog Pinia FavoritesSkills Dir β†’