PyWin32 (226) and virtual environments

前端 未结 1 531
挽巷
挽巷 2020-12-19 12:08

[PyPI]: pywin32 226 has been released on 20191110.
It works on most of the Python installations (e.g. works on the official v

1条回答
  •  Happy的楠姐
    2020-12-19 12:33

    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:
      • v226 is OK
    • VirtualEnvs (and also Python's standard venvs):
      • v225 is OK
      • For Python 3.8.0, [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 should be used

    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!

    0 讨论(0)
提交回复
热议问题