fix(windows): pip self-upgrade lock + GBK emoji crash on first-run venv setup#33
Open
aiking931931 wants to merge 1 commit into
Conversation
Two Windows-only blockers prevented first-run venv setup from completing on default Windows installs: 1. setup_environment.py — pip self-upgrade via the .exe wrapper crashes with exit 1 because the running pip.exe is file-locked by the OS even after the upgrade succeeds. Switch to the module entry point (python -m pip install --upgrade pip) which avoids the self-replace, and stop relying on check=True for the upgrade step. Detect success by stdout marker (Successfully installed / already satisfied) so a benign non-zero exit no longer aborts the whole setup. Also switch the requirements install to python -m pip for consistency. 2. run.py — print() calls with emoji characters (U+1F527, U+1F680, U+2705 etc) crash on Windows consoles whose default encoding is GBK (cp936) or cp1252, raising UnicodeEncodeError before any of the actual logic runs. Add a tiny header right after import sys that calls sys.stdout.reconfigure(encoding="utf-8") / sys.stderr.reconfigure(encoding="utf-8") when os.name == "nt". Wrapped in try/except so older Python versions and non-stream stdout (CI capture) still no-op cleanly. Tested on Windows 11 26200 / Python 3.13 / GBK default console. Unix (Linux / macOS) unaffected — the os.name == "nt" guard scopes the encoding fix to Windows only; python -m pip is the documented portable form on every platform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two Windows-only blockers stopped first-run venv setup from completing on default Windows installs (Python 3.13 / Win 11 / GBK console). Both fixes are scoped to Windows via
os.name == 'nt'and stay no-op on Linux / macOS.Bug 1 —
scripts/setup_environment.pypip.exe install --upgrade pipcrashes with exit 1 on Windows even after the upgrade succeeds, because the runningpip.exeis file-locked by the OS while it tries to overwrite itself.subprocess.run(check=True)then aborts the whole setup, so the venv never gets dependencies installed.Fix: switch to the documented portable form
python -m pip install --upgrade pip, dropcheck=Truefor the upgrade step, and detect success by stdout marker (Successfully installed/already satisfied). The requirements install is also moved topython -m pipfor consistency.Bug 2 —
scripts/run.pyprint()calls with emoji (🔧 🚀 ✅UnicodeEncodeError— before any of the actual logic runs.Fix: add a tiny header right after
import systhat callssys.stdout.reconfigure(encoding="utf-8")and the same onsys.stderrwhenos.name == "nt". Wrapped intry/except (AttributeError, ValueError)so older Python versions and non-stream stdout (CI capture) still no-op cleanly.Repro
Before the fix, on stock Windows 11:
```
rd /s /q .venv
python scripts/run.py auth_manager.py status
```
— first attempt aborts during pip self-upgrade (exit 1, file lock); second attempt aborts on `UnicodeEncodeError` printing the emoji header.
After the fix:
```
rd /s /q .venv
set PYTHONIOENCODING=utf-8
python scripts/run.py auth_manager.py status
```
— venv builds, deps install, status command runs and prints the emoji output without crashing.
Test plan
Notes
🤖 Generated with Claude Code