Fixed: "warning: Failed to parse environment file .env at position 6" with uv run
uv run --env-file .env should have put one variable into my script's environment. Instead uv printed "warning: Failed to parse environment file .env at position 6" and the script failed with KeyError. The cause was one missing pair of quotes. Here's how I found it, with real output from uv 0.13.10.
What I Was Doing
I was writing an example for loading a .env file with uv: one variable in the file, and a script that prints it.
GREETING=Hello from the .env file
import os
print(os.environ["GREETING"])
What I Expected
Hello from the .env file
What I Got
uv run --env-file .env show_env.py
warning: Failed to parse environment file `.env` at position 6: Hello from the .env file
Traceback (most recent call last):
File "/Users/you/source/python-basics/show_env.py", line 3, in <module>
print(os.environ["GREETING"])
~~~~~~~~~~^^^^^^^^^^^^
File "<frozen os>", line 729, in __getitem__
KeyError: 'GREETING'

It's only a warning, so uv ran the script anyway, without the variable, and the script failed on its first line.
What I Checked
1. Where the position points. The message quotes the value, Hello from the .env file. Counting from 0 in that value, position 6 is just after Hello , the start of from: the parser stopped at the first word after a space.
2. uv's documentation on .env files. The configuration files page says uv run reads dotenv files "powered by the dotenvy crate", and its own example puts a value with a space in quotes: MY_VAR='Hello, world!'.
3. The dotenvy parser's example file. dotenvy's own example .env writes spaces in an unquoted value only escaped, as in not\ quoted\ with\ escaped\ space, and puts other values with spaces in quotes, as in "double quoted with # hash in value".
Why It Happens
uv doesn't read .env itself; the dotenvy parser does. An unquoted value ends at the first unescaped space, so the rest of the line, from the .env file, couldn't be parsed. uv reported it, stopped reading the file there, and ran the script without the variable.
The Fix
Quote the value:
GREETING="Hello from the .env file"
Single quotes work too.
After the Fix
uv run --env-file .env show_env.py
Hello from the .env file

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| A value with spaces and no quotes | The parse warning, and the variables are missing | Quote the value |
| Ignoring the warning because the script runs | The script fails later, often with a KeyError | Treat the warning as an error and fix the file |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The warning names another position | A different value has a space, or a quote that doesn't close | Count from the start of the value the warning quotes; Hi there stops at position 3 |
FAQ
Do other tools read the same file the same way?
Not always. Some dotenv readers accept unquoted spaces. Quoting values with spaces works everywhere.
Does one bad line lose the whole file?
It loses that line and every line after it. In a two-line test with FIRST=one above SECOND=Hi there, the warning named position 3 and only FIRST was set. With the bad line first, neither was. Fix the line in the message, then run again, since a later line can have the same problem.
Conclusion
The .env value Hello from the .env file had spaces and no quotes, so uv's dotenvy parser stopped at position 6 and the script got no GREETING. Writing it as GREETING="Hello from the .env file" fixed it.
Additional Resources
- Environment variable files — how
uv runloads.envfiles. - dotenvy — the parser uv uses, with its example
.env.
