PyWin32 (226) and virtual environments

懵懂的女人 提交于 2019-12-06 06:32:58

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)):

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:\Work\Dev\StackOverflow\q058805040]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***

[prompt]> ".\venv_py_064_030800\Scripts\python.exe" -m pip list
Package    Version
---------- -------
pip        19.3.1
pywin32    226
setuptools 41.6.0
wheel      0.33.6

[prompt]> ".\venv_py_064_030800\Scripts\python.exe" -c "import win32api"

[prompt]>


Update #0:

[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114 !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!