How to fix "playwright: command not found"?

Playwright

playwright: command not found (or 'playwright' is not recognized as an internal or external command on Windows, zsh: command not found: playwright on macOS) means your shell can't find a playwright executable on its PATH. Playwright is installed as a project dependency, not as a system command. For Node.js, the playwright binary lives in node_modules/.bin/, which is only on PATH when you run it through npx, a package script, or pnpm exec. For Python, pip install playwright puts the script in a user bin directory (such as ~/.local/bin) that is often not on PATH.

Common mistake

# Node: package is installed, but node_modules/.bin is not on PATH
npm install -D @playwright/test
playwright install
# zsh: command not found: playwright
# Python: pip installed the package, but the script dir is not on PATH
pip install playwright
playwright install
# bash: playwright: command not found

Also common: the package was never installed in this directory, or you installed it in a different Node version (nvm) than the one active in the current shell.

The fix

Node.js: run the CLI through your package runner instead of calling playwright directly.

# npm
npx playwright install
npx playwright test

# pnpm
pnpm exec playwright install

# yarn
yarn playwright install

If the command is part of a workflow, put it in package.json scripts. Scripts get node_modules/.bin on PATH automatically:

{
  "scripts": {
    "pw:install": "playwright install --with-deps",
    "test:e2e": "playwright test"
  }
}
npm run pw:install

If you see command not found even with npx, the package is missing. Install it first:

npm install -D @playwright/test
npx playwright install

Python: call it as a module, which bypasses PATH entirely:

pip install playwright
python -m playwright install
python -m playwright install --with-deps chromium

If you prefer the bare playwright command, add the script directory to PATH:

# Linux / macOS (add to ~/.zshrc or ~/.bashrc)
export PATH="$HOME/.local/bin:$PATH"

On macOS with a framework Python the directory may be ~/Library/Python/3.x/bin. Run python -m site --user-base and append /bin to see where pip puts scripts. On Windows, use py -m playwright install or add the Scripts folder of your Python install to PATH.

Global install (not recommended): if you really want a system-wide command, install it globally and make sure npm's global bin directory is on PATH:

npm install -g playwright
npm config get prefix   # global bin is <prefix>/bin
export PATH="$(npm config get prefix)/bin:$PATH"

Docker and CI: use npx (or python -m playwright) in the RUN step and install dependencies before it:

FROM node:20-bookworm-slim
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
RUN npx playwright install --with-deps chromium

Why it works

A shell resolves a command by walking the directories in PATH. npm install doesn't modify your PATH; it drops symlinks into node_modules/.bin, and only npx, pnpm exec, yarn, and npm run add that directory for the duration of the call. Likewise pip writes console scripts into a per-user or per-environment bin directory that your shell only sees if it's listed in PATH or the virtualenv is activated. python -m playwright skips the lookup because Python finds the module through its own import path rather than through the shell.

Tips

  • After the command works, you may still hit Executable doesn't exist. That means the CLI runs but the browser binaries haven't been downloaded. playwright install fixes it.
  • With a Python virtualenv, activate it (source .venv/bin/activate) before running playwright. A fresh terminal or a CI step that doesn't activate the venv won't see the script.
  • With nvm, a new shell may switch to a different Node version, and global packages installed under another version disappear. Prefer project-local installs plus npx.
  • In monorepos, run npx playwright from the package that depends on @playwright/test, or use pnpm --filter <package> exec playwright install.
  • Pin the @playwright/test version in package.json so npx never downloads a different version on the fly.
  • On Linux CI images, add --with-deps so the OS libraries Chromium needs are installed too. See CI missing OS deps and fonts if the browser installs but crashes on launch.
  • The newer agent CLI is installed as playwright-cli (with a hyphen), not playwright. See Playwright CLI: every command you actually use for both CLIs.

Scraping with Playwright?

If you're setting up Playwright for a scraper, see Web Scraping with Playwright for waiting, memory, blocking and deployment fixes in one place. If you only need the page content and not a browser session, one API request returns it as Markdown or HTML without installing or running Chromium yourself.