2025, Nov 02 03:00
Why ./test.py Fails with an ICU Error on Windows and How to Run Python Scripts Correctly
ICU error running ./test.py on Windows? See why shebangs and .py associations fail, how to fix them (assoc, ftype), and run scripts via python test.py.
Running a Python script directly as ./test.py in Windows 10 can unexpectedly fail with an ICU error, while the same code works with python ./test.py. If this looks odd in VS Code’s integrated terminal with a fresh python.org install, the reason is not the code itself but how Windows handles executable files compared to Linux-like environments.
Reproducing the issue
Consider a minimal script saved as test.py with a Unix-style shebang at the top.
#!/usr/bin/env python
print("Hello World")Invoking it this way triggers the error:
./test.pyBut calling the interpreter explicitly runs fine:
python ./test.pyThe observed error looks like this:
[0711/233305.303:ERROR:icu_util.cc(223)] Invalid file descriptor to ICU data received.What’s actually going on
Two Linux conventions sneak in here: the path prefix ./ and the shebang #!/usr/bin/env python. Windows does not use forward slashes as a path separator in this context and does not honor that shebang to locate the interpreter. When you run ./test.py on Windows, the system does not execute it “through the shebang”; instead, it relies on the registered file association for .py files. If this association is missing or points to an unexpected target, you may hit the ICU-related error you are seeing. In contrast, python ./test.py directly invokes the Python interpreter you installed, bypassing the association problem entirely.
If you want to confirm which interpreter actually runs your script under different invocations, temporarily print the executable path:
import sys
print(sys.executable)How to fix or avoid the ICU error
The most reliable way to avoid this is to call Python explicitly, for example python test.py. Removing the Unix shebang from the script helps keep expectations clear on Windows. If you prefer running scripts by name without typing python first, make sure Windows has a correct file association for .py files.
First, try the simplest approach: run the script by name without the ./ prefix. In a correctly configured Windows shell, typing test.py and pressing Enter should launch the script via the .py association. If that doesn’t work or produces the ICU error, set or repair the association. You can do this through the UI by choosing Open With → Choose another program and selecting python for .py files. Alternatively, use the following commands in an elevated Command Prompt (adjust the path to your python.exe):
assoc .py=Python.File
ftype Python.File="C:\Path\To\python.exe" "%1" %*If the association still behaves strangely, reinstalling Python can restore the correct setup. After that, keep using either python test.py or just test.py without the ./ prefix.
Corrected minimal script
There is no need for a Unix shebang on Windows. The script itself can stay minimal; here’s a clean version.
greeting_text = "Hello World"
print(greeting_text)Why this matters
Cross-platform habits can leak into Windows workflows and cause confusing toolchain errors that look like runtime or library problems. The icu_util.cc message is a symptom of how the script was launched, not of the Python code. Understanding that Windows uses file associations for .py files, ignores Unix shebangs, and does not use ./ as a path prefix helps you avoid time-wasting detours.
Takeaways
On Windows, don’t rely on ./ or a Unix-style shebang to run Python scripts. Prefer python test.py or, with a correct .py association, simply test.py. If you encounter the ICU error when running a script directly, repair the .py association using Open With or the assoc and ftype commands, or reinstall Python. When in doubt, print(sys.executable) to verify the interpreter actually being used.