Skip to content

fix: Windows compatibility - bypass missing 'pwd' module for Torch#262

Open
MakeHorizont wants to merge 1 commit intomicrosoft:mainfrom
MakeHorizont:patch-2
Open

fix: Windows compatibility - bypass missing 'pwd' module for Torch#262
MakeHorizont wants to merge 1 commit intomicrosoft:mainfrom
MakeHorizont:patch-2

Conversation

@MakeHorizont
Copy link
Copy Markdown

Summary

This PR fixes a critical crash on Windows where the application fails to start due to ModuleNotFoundError: No module named 'pwd'.

The Problem

The error occurs when torch (specifically torch._inductor) attempts to determine the user's home directory for caching using Unix-only modules. On Windows, this leads to the following traceback:

text :
File "getpass.py", line 168, in getuser
import pwd
ModuleNotFoundError: No module named 'pwd'

The Solution

I have added a platform-check at the beginning of demo/gradio_demo.py to:
Manually define the USER environment variable.
Explicitly set TORCHINDUCTOR_CACHE_DIR to the system's temp folder.
This allows the script to initialize correctly on Windows systems without requiring the user to manually set up environment variables in their shell.

Testing

Verified on Windows 10/11: the Gradio interface now launches successfully on port 7860 as expected.

Added a workaround for Windows systems to prevent a crash caused by the missing 'pwd' module. By manually setting 'USER' and 'TORCHINDUCTOR_CACHE_DIR' environment variables at the entry point, we bypass the Unix-specific user lookup in torch._inductor, allowing the demo to run on Windows without manual environment configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant