Fix pywin32_bootstrap.py to handle early initialization environments#2596
Fix pywin32_bootstrap.py to handle early initialization environments#2596Devel-Dan wants to merge 2 commits intomhammond:mainfrom
Conversation
33f3e9c to
03cd054
Compare
There was a problem hiding this comment.
[...] 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 <samuel.06@hotmail.com>
|
Pinging @mhammond to see if you're ok re-introducing this code or would also prefer first 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 |
|
@Devel-Dan Have you raised this issue to Pylance to see if they're doing something weird ? https://github.com/microsoft/pylance-release/issues/
Do you have examples or links of other users hitting this or similar issue ? |
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: