fix: Windows compatibility - bypass missing 'pwd' module for Torch#262
Open
MakeHorizont wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: Windows compatibility - bypass missing 'pwd' module for Torch#262MakeHorizont wants to merge 1 commit intomicrosoft:mainfrom
MakeHorizont wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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.
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
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.