Windows Dev-Environment Gotchas That Eat a Day

Date:

A running field guide to the traps that bite a Windows dev box day after day – the ones that are small on their own and expensive in aggregate. Each is written as a thirty-second diagnosis.

The short answer: On a Windows machine driving a Unix-style toolchain – Git Bash or MSYS2, a real Postgres, Python, a scheduler, git hooks – the same handful of traps recur: the shell’s PATH drops tools mid-session, a hook calls python3 when only python exists, psycopg can’t find libpq, a background-process test fails only in automation, and a long command piped to tail looks hung at zero bytes. None is exotic and each wastes an hour the first time. This is the catalog, each entry as symptom, cause, fix, and – the part that pays off – how to avoid it next time. It is deliberately a list you append to; new traps join as they recur. If you want the one-time setup that prevents a different class of problem, see turning Windows into a dev workstation with one script; this page is the traps that still bite after the box is set up.

Why a Windows dev environment keeps biting

A Windows box running a Unix toolchain lives at a seam: POSIX tools expect a POSIX environment, and the real one underneath is Windows. Most of the day that seam is invisible. The traps below are the places it shows through – path translation, interpreter names, native library loading, process identity, pipe buffering. Written down, each becomes a pattern you recognize on sight instead of a fresh afternoon.

command not found for tools that are installed

  • Symptom: mid-session, grep, head, python, git, or gh report command not found – tools that worked minutes ago.
  • Cause: the shell’s PATH got trimmed or reset between invocations, dropping the MSYS/Git-Bash bin directories and your language toolchains. The binaries are still on disk; the shell just can’t see them.
  • Fix: prepend an explicit PATH at the top of the command: export PATH="/mingw64/bin:/c/Program Files/Git/usr/bin:/usr/bin:$PATH".
  • Avoid: make that export a reflex at the start of any shell block that uses coreutils or a runtime. Don’t trust an inherited PATH to still hold what it did last time.

python3: command not found, but python works

  • Symptom: a git hook or script dies on python3: command not found, though Python is installed and python runs fine.
  • Cause: the Windows Python installer lays down python.exe (and sometimes python3.exe), but a Unix script hard-codes python3, which isn’t on PATH. A well-written hook probes for the interpreter and falls back – but only if one of the two names is reachable.
  • Fix: put the Python directory on PATH so the probe resolves a name it can run.
  • Avoid: when you write a hook, probe for the interpreter (PYBIN=python; command -v python >/dev/null || PYBIN=python3) instead of assuming a name; when you run something with a hook, confirm an interpreter is on PATH first.

libpq not found – psycopg won’t import

  • Symptom: a Python process that uses psycopg fails at import with no pq wrapper available ... libpq library not found, even inside the right virtual environment.
  • Cause: psycopg needs the libpq client library at runtime. On Windows it ships with PostgreSQL, in that install’s bin directory, which isn’t on PATH by default.
  • Fix: add the Postgres bin to PATH before running anything that imports psycopg: export PATH="/c/Program Files/PostgreSQL/16/bin:$PATH".
  • Avoid: bundle the Postgres bin into the standard PATH prefix you use for database work, next to the virtual environment’s scripts. If a suite fails only when a hook runs it, this is a prime suspect – hooks inherit a thinner environment than your shell.

A background-process test fails only in automation

  • Symptom: a test that launches a child process and checks whether its process id is “live” fails deterministically in CI or a sandbox – reporting zero live workers – while passing when you run it by hand.
  • Cause: process-liveness checks on Windows often go through the OS process table, and a background job started under a nested or sandboxed shell may not resolve to a live id the way the test expects. The test is measuring an environment property, not your code.
  • Fix: confirm it is pre-existing and environment-specific by running the same test against the unchanged main branch. If it fails there too, your change didn’t cause it – don’t chase it.
  • Avoid: don’t gate a code change on an environment-dependent liveness test; mark such a test to skip off its platform, and verify it against the real way it will be invoked, not only your interactive shell.

A test that doesn’t use the caller’s real input shape measures the wrong thing.

A long command piped to tail looks hung at zero bytes

  • Symptom: you run a long job and pipe it through tail or head to keep output small; the output stays empty for ages and you can’t tell whether it is working or wedged.
  • Cause: the pipe buffers. The downstream tail emits nothing until the upstream closes or a full buffer flushes, so a healthy long job and a hung one look identical – both show nothing.
  • Fix and avoid: never pipe a long job through tail/head for progress. Redirect to a logfile and read that instead: long_job > run.log 2>&1 &.

A silent pipe is not evidence of a hang; it’s evidence you can’t see.

git -C /c/work/... silently acts on the wrong directory

  • Symptom: a git -C <path> command appears to succeed but acts on the repository you are standing in, not the one you named. If a pre-command hook or wrapper checks which repository a git call targets, it may block the command for reasons that make no sense at first.
  • Cause: MSYS path translation. A lowercase drive path like /c/work/repo isn’t always resolved as you expect and can fall back to the current directory; the Windows-style C:/work/repo is unambiguous.
  • Fix and avoid: use the drive-letter form (C:/work/...) for git -C, and keep it to one simple git call per invocation so a silent fallback can’t hide inside a compound command.

Backslashes get mangled when you author code through a heredoc

  • Symptom: code you wrote via a shell heredoc raises a strange, unrelated error later, somewhere else – a doubled backslash collapsed, a \t became a real tab, a regex backreference turned into a control character.
  • Cause: the shell processes escapes before your content is ever written, silently corrupting anything with backslashes. Editors render control characters as nothing, so the file looks correct.
  • Fix and avoid: author anything with backslashes – regexes, Windows paths, escape sequences – with a real file-writing tool, not a heredoc. To inspect for hidden damage, use cat -A or Python’s repr() rather than a normal read.

The short version

  • Most Windows dev-environment pain lives at one seam: POSIX tools on a non-POSIX host. The traps cluster around PATH, interpreter names, native libraries, process identity, and pipe buffering.
  • A PATH prefix is the single highest-value reflex: it fixes “command not found,” the python3 miss, and libpq not found in one line.
  • Verify environment-dependent failures against main before you chase them – a test that fails the same way on unchanged code is not your bug.
  • Never read progress through a buffering pipe; redirect to a log.
  • This list is meant to grow. Each trap written down is a trap that only costs the first person, once.

Frequently Asked Questions

Why does psycopg fail with “libpq library not found” only inside a hook or CI?

psycopg loads the native libpq client library at runtime, which on Windows ships inside the PostgreSQL install’s bin directory and is not on PATH by default. Your interactive shell may happen to have it; a git hook or CI job runs with a thinner environment and does not. Adding the Postgres bin to PATH before the process starts fixes it in both places.

Can I make the PATH prefix permanent instead of typing it each time?

Partly. An export PATH=... line in ~/.bashrc covers the interactive Git Bash shells you open yourself. Hooks, schedulers and other non-interactive shells usually don’t read ~/.bashrc, so they still start with a thinner PATH. Keep the profile line for your own shells and the explicit prefix in anything that runs unattended.

Would WSL make these traps go away?

Most of them, while you stay inside it. WSL 2 runs a real Linux system, so interpreter names, libpq and pipe behavior work as they do on Linux. It adds a seam of its own: files on the Windows drive (under /mnt/c) are much slower to work with from Linux, and Windows programs can’t run Linux tools directly. Keep the repo and its toolchain on one side of the boundary.

Share post:

Subscribe

Popular

More like this
Related

WooCommerce Search by SKU or ISBN Finds Nothing? It Never Looks There

A shopper types the SKU from your catalog, or the ISBN printed on the back of a book, and gets "No products were found". The product is right there, and the number is on its page. Search simply never reads that part of the product.

Computer Slow but CPU and Memory Look Normal? Check the Handle Count

Chrome takes a minute to open, or doesn't open at all. Every click waits. You open Task Manager expecting to find the culprit, and it tells you everything is fine. Here is the number that isn't, and the fix that takes two minutes.

Kernel-Power 41 Tells You Your PC Restarted, Not Why

Your PC restarts with no blue screen, and the only clue is a critical event saying it didn't shut down cleanly. Here is how to get from that event to a short list of suspects.

Set Up WordPress SMTP Without a Plugin, Even on a Multisite Network

WordPress mail goes out as wordpress@ your domain, from the web server, and lands in spam. An SMTP plugin fixes that. So do about twenty lines of code, and on a network of sites the code can give every site its own mailbox and its own password.