Note: I branched this answer (and also the question) from [SO]: PyWin32 and Python 3.8.0 (@CristiFati's answer), as it's a different issue. You might want to check that one before going further.
After some digging, it turns out it's a VirtualEnv bug (or at least, that's how I see things, because VirtualEnv's site.py doesn't contain getsitepackages - although it was present in Python's site.py since v2.7).
There are several issues (that were) open revolving this absence (e.g. [GitHub]: pypa/virtualenv - site.getsitepackages() missing), but they appear to be closed without a fix (many of them due to inactivity). Also, [GitHub]: [WIP] The next-gen virtualenv (rewrite) which is a big refactor, doesn't seem to address it.
Recap: this error (in VirtualEnv context):
- Also applies to other Python versions (I can confirm for v3.7.3 (32bit))
- Happens every time when the interpreter starts
In conclusion, do not install PyWin32 226 in (VirtualEnv) virtual environments, as they will end up in a broken state!
PyWin32 (official .whls) "compatibility table" (didn't check Anaconda (or other such tools)):
- "Normal" (official) Python installations:
- VirtualEnvs (and also Python's standard venvs):
Submitted [GitHub]: mhammond/pywin32 - Workaround for virtual environments (VirtualEnv) (merged on 20191114). Applying the changes locally (check the referenced question for details on how to do it), fixed it:
[cfati@CFATI-5510-0:e:WorkDevStackOverflowq058805040]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> ".venv_py_064_030800Scriptspython.exe" -m pip list
Package Version
---------- -------
pip 19.3.1
pywin32 226
setuptools 41.6.0
wheel 0.33.6
[prompt]> ".venv_py_064_030800Scriptspython.exe" -c "import win32api"
[prompt]>
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…