-
Notifications
You must be signed in to change notification settings - Fork 824
Fix pywin32_bootstrap.py to handle early initialization environments #2596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix pywin32_bootstrap.py to handle early initialization environments #2596
Conversation
33f3e9c
to
03cd054
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] address issues occurring during very early Python initialization, particularly in VS Code's Python extension (Pylance/IntelliSense).
[...] neither os.add_dll_directory() nor even os.environ['PATH'] may be fully available yet
Can you give an example (MRE) demonstrating this, (and fixed by this patch)? Especially if it fixes an existing issue in https://github.com/mhammond/pywin32/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20(path%20OR%20DLL)
A test would go a long way in demonstrating the use case(s) and preventing regressions. For example, very similar code (which also made sure to avoid duplicating the PATH addition) was removed in https://github.com/mhammond/pywin32/pull/2207/files#diff-a9afdb98cf78a938058e200c4603b1c1fb5465202d6f69ee23458ce5e7e3b668 as an "obsolete code path" as part of dropping support for Python 3.7. (since add_dll_directory
is expected to always exist on Python >= 3.8)
Could you confirm on which version of Python you are trying to run this as well?
I was using python 3.13.1 I don't think the version matters here though
I tried doing what that attribute was performing and adding to "PATH" but i got this
It seems like this issue is occurring because VS Code is processing this .pth file too early? - before the environment is fully initialized. |
Thanks for the additional details. I'm still trying to at least replicate your issue. So it can be checked for in the future, or seeing if it's a Pylance issue that can be raised there (because it's a really odd issue) My setup: Pylance
Pylance
|
Co-authored-by: Avasam <[email protected]>
Pinging @mhammond to see if you're ok re-introducing this code or would also prefer also understanding why Pylance even fails here. |
yeah the only difference with our tests is that I did not use a virtual environment, which is probably the fix here, I think I've seen solutions from other people saying this, just using conda for example |
Fix pywin32_bootstrap.py to handle early initialization environments
This patch adds robust error handling to pywin32_bootstrap.py to address
issues occurring during very early Python initialization, particularly
in VS Code's Python extension (Pylance/IntelliSense).
Problem:
During early initialization when .pth files are processed, neither
os.add_dll_directory() nor even os.environ['PATH'] may be fully available
yet, causing errors like:
Solution: