[PyPI]:pywin32 226已于 20191110 发行。 它 适用 于大多数 Python 安装程序( 例如, 适用于从Python下载的正式版本),但 不适 用于虚拟环境( 例如 ,使用 VirtualEnv ( v16.7.7 )和(基于进一步的研究) Python 的 venv创建 )。 我将 Python v3.8 .0和 v3.7 .3用作实验大鼠。这是前者的输出:
[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q058805040]> “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe” -c “import win32api” Fatal Python error: init_import_size: Failed to import the site module Python runtime state: initialized Traceback (most recent call last): File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 769, in main() File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 746, in main paths_in_sys = addsitepackages(paths_in_sys) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 279, in addsitepackages addsitedir(sitedir, known_paths) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 202, in addsitedir addpackage(sitedir, name, known_paths) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 170, in addpackage exec(line) File ““, line 1, in File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site- packages\win32\lib\pywin32_bootstrap.py”, line 14, in for maybe in site.getsitepackages(): AttributeError: partially initialized module ‘site’ has no attribute ‘getsitepackages’ (most likely due to a circular import)
[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q058805040]>
“e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe” -c “import win32api” Fatal Python error: init_import_size: Failed to import the site module Python runtime state: initialized Traceback (most recent call last): File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 769, in main() File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 746, in main paths_in_sys = addsitepackages(paths_in_sys) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 279, in addsitepackages addsitedir(sitedir, known_paths) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 202, in addsitedir addpackage(sitedir, name, known_paths) File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py”, line 170, in addpackage exec(line) File ““, line 1, in File “e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site- packages\win32\lib\pywin32_bootstrap.py”, line 14, in for maybe in site.getsitepackages(): AttributeError: partially initialized module ‘site’ has no attribute ‘getsitepackages’ (most likely due to a circular import)
注意 :我从[SO]分支了这个答案(也是问题):PyWin32和Python 3.8.0(@CristiFati的答案),因为这是一个不同的问题。您可能需要检查一下,然后再继续。
经过一番挖掘后,发现这是一个 VirtualEnv 错误(或者至少是我所看到的,因为 VirtualEnv 的 site.py 不包含 getsitepackages- 尽管自 v2.7 起它就存在于 Python 的 site.py中) )。围绕着这种缺席存在着一些尚未解决的问题( 例如 [GitHub]:pypa / virtualenv- site.getsitepackages()missing),但是它们似乎没有任何解决就被关闭了(其中许多是由于不活动)。另外,[GitHub]:[WIP]下一代virtualenv(重写)是一个很大的重构,似乎并没有解决。
概述 :此错误(在 VirtualEnv 上下文中):
总之, 请勿 在( VirtualEnv )虚拟环境中安装 PyWin32 226 ,因为它们最终将处于损坏状态! __
PyWin32 (官方 .whl )“兼容性表”(未检查 Anaconda (或其他此类工具)):
提交 [GitHub]:mhammond / pywin32-虚拟环境的解决方法(VirtualEnv) ( 于 20191114 合并 )。在本地应用更改(请检查参考的问题以获取有关如何执行更改的详细信息),并进行以下修复:
[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]>
[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]>
[PyPI]:pywin32 227 (解决了此问题),已于 20191114 发布!