我刚刚升级到Python 3.8.2。升级后,我重新安装了一些经常使用的软件包:
python -m pip install --upgrade pip
pip install -U wxPython
pip install pywin32
pip install python-vlc
pip install PyAutoIt
现在我发现我无法再创建COM对象。一个最小的例子是
import win32com.client
aut = win32com.client.Dispatch("AutoItX3.Control")
此结果导致
Traceback (most recent call last):
File "C:\Python\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\testwin32.py", line 2, in <module>
aut = win32com.client.Dispatch("AutoItX3.Control")
File "C:\Python\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
这是Python 3.8.2,win32com的问题,还是我需要重新初始化?
发现了问题。当我安装Python 3.8.2时,我获取了32位版本。我使用64位版本重新安装,问题消失了。