跳到正文

第 2 课 · Getting Started

Install DVC and Initialize a Project

Install DVC with pip, pipx or conda, add the storage extras you need, run dvc init in a Git repository and learn what each new file does.

Before you can version any data, you need two things: the dvc program on your computer and a project where it is switched on. Both take only a few minutes. This lesson also explains the files that appear, so nothing in your repository feels mysterious.

Install DVC

DVC is a Python application, and there are several ways to install it. As of December 2026, the official installation pages describe pip, conda (from the conda-forge channel), snap on Linux, and system packages or package repositories. The pip instructions say the latest release needs Python 3.9 or newer. Requirements change, so check the official install page for your operating system.

For a per-project setup, use a virtual environment. It keeps DVC's dependencies away from your other tools.

Terminal
# Read-only: a virtual environment with DVC inside
python -m venv .venv
source .venv/bin/activate        # Windows PowerShell: .venv\Scripts\Activate.ps1
pip install dvc
dvc version

If you prefer one dvc command for every project, pipx install dvc is a common choice. The documentation strongly recommends a virtual environment or pipx over a global pip install.

Storage extras

The base package can use a local folder as storage. Cloud and server backends need extra libraries. With pip you request them as extras:

Storage pip command
Amazon S3 and compatible services pip install "dvc[s3]"
Google Cloud Storage pip install "dvc[gs]"
Azure Blob Storage pip install "dvc[azure]"
SSH and SFTP pip install "dvc[ssh]"
Google Drive pip install "dvc[gdrive]"
Everything pip install "dvc[all]"

With conda, the equivalents are separate packages such as dvc-s3 or dvc-ssh. Install only what you use: fewer packages mean fewer conflicts. Pin the version in your requirements file so that teammates and your CI server run the same DVC.

Initialize a project

DVC normally lives inside a Git repository, so create that first if needed.

Terminal
# Read-only: start a new project
mkdir review-model && cd review-model
git init
dvc init
git status
git commit -m "Initialize DVC"

dvc init creates a .dvc/ folder and stages its new files for you, so a single commit records the setup. Here is what you will find, now or after you start using DVC:

Path Purpose In Git?
.dvc/config Project settings, shared with the team Yes
.dvc/config.local Your private settings, such as credentials No
.dvc/cache/ Stored file contents No
.dvc/tmp/ Locks and temporary files No
.dvc/.gitignore Keeps the three ignored items out of Git Yes
.dvcignore Patterns DVC should skip Yes

You can read .dvc/config at any time. It is a plain INI-style file, and dvc config edits it for you.

Two special options

  • dvc init --subdir initializes DVC in a subfolder of a larger Git repository. This helps in a monorepo where only one folder needs data versioning.
  • dvc init --no-scm sets up DVC without Git. You lose features that depend on Git, such as comparing revisions and automatic .gitignore updates. Use it only for special cases.

dvc init --force removes an existing .dvc/ folder first, including the local cache. Do not use it on a project whose data you have not pushed somewhere safe.

Configuration levels

DVC reads settings from four places. A setting closer to your project wins.

  1. Local (.dvc/config.local): private, never committed. Highest priority.
  2. Project (.dvc/config): shared through Git.
  3. Global: your user account on this machine.
  4. System: every user on the machine.
Terminal
# Read-only: setting options at different levels
dvc config core.autostage true            # project
dvc config --local core.autostage false   # only for you
dvc config --global core.analytics false  # all your projects

core.autostage makes DVC run git add on the files it creates or changes (it never commits). core.analytics controls anonymized usage statistics, which are on by default. If your company has rules about telemetry, set it before you start.

The stand-in below shows how the priority order resolves settings. It is not DVC's configuration code.

Python Stand-in: resolving configuration levels

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your setup

Run dvc doctor to print the version, Python, platform and the storage backends that are available. Include this output when you ask for help, after you check it for private paths or names.

Common mistake: committing secrets in .dvc/config. That file is shared through Git. Put passwords, keys and tokens in the local level with --local, or use your cloud provider's standard credential tools.

Shell completion and an extension for VS Code also exist. Both are optional, and the command line stays the reference for everything in this course. After setup, make one empty commit history you trust: run git log --oneline and confirm that the "Initialize DVC" commit is there.

Record your versions

Reproducibility starts with knowing what you ran. Add DVC to a requirements file with an exact version, for example by running pip freeze and copying the relevant lines. If you use extras, keep the extra in that line so that a new machine installs the storage library too. Upgrade on purpose: change the pin on a branch, run your pipeline and checks, and merge only when they pass.

When you upgrade across major versions, read the upgrade notes first. For example, the documentation has a dedicated page about upgrading to DVC 3.0, because the cache layout and some behaviors differ from earlier versions. Teammates who use mixed major versions on one project can get confusing results.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. You want to use an S3 bucket as storage after a pip install. What do you add?

    Cloud backends need optional dependencies, requested as pip extras.
  2. 2. Which file is the right place for a private password?

    The local config file is ignored by Git and overrides the project file.
  3. 3. What is risky about dvc init --force on an existing project?

    Cached data that exists nowhere else would be lost.
  4. 4. Which level has the highest priority?

    Local settings override project, global and system settings.

Summary

  • Install DVC in a virtual environment or with pipx, and pin its version.
  • Add storage extras only for the backends you use.
  • Run dvc init inside a Git repository and commit the files it stages.
  • .dvc/config is shared; .dvc/config.local is private and wins over it.
  • dvc doctor shows your environment when something looks wrong.

Next: How DVC Works: Hashes, Cache and Links

你的学习进度保存在此浏览器中,无需账号。