注:質問はもともと Python と に関するものでしたがwin32com
、問題はクライアント側ではなく、COM サーバー内に存在することが判明しました。したがって、質問と回答の情報は、COM クライアントとして使用できるすべての言語に適用されます。
多分誰かが助けることができます。私が直面しているのは、次の状況です。VisualStudio.VCProjectEngine.8.0
私のコードで問題なくインスタンス化できます。関連するコード:
import win32com
vcver = {
'VisualStudio.VCProjectEngine.8.0' : ('{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}', 0, 8, 0),
'VisualStudio.VCProjectEngine.10.0' : ('{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}', 0, 10, 0),
}
for ProgID, vc in vcver.iteritems():
# Error also happens without the following line
win32com.client.gencache.EnsureModule(vc[0], vc[1], vc[2], vc[3])
o = win32com.client.gencache.GetClassForProgID(ProgID)()
if o:
try:
# The following line causes the exception ...
o.CreateProject('test')
print "Success for %s" % ProgID
except Exception as e:
print str(e)
raise
...このエラーが発生します:
Success for VisualStudio.VCProjectEngine.8.0
(-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Traceback (most recent call last):
File "D:\scriptname.py", line 123, in <module>
o.CreateProject('test')
File "C:\Users\Username\AppData\Local\Temp\gen_py\2.7\0CD36BB6-D828-4DB9-91BF-AD493EE76B79x0x10x0.py", line 2756, in CreateProject
ret = self._oleobj_.InvokeTypes(213, LCID, 1, (9, 0), ((8, 1),),projectName
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
ご覧のとおり、一方は正常に動作し、もう一方は不可解に失敗します。何を与える?
makepy.py -i
与えるものは次のとおりです。
>makepy.py -i VisualStudio.VCProjectEngine.8.0
VCProjectEngineLibrary
{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}, lcid=0, major=8, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}', 0, 8, 0)
>makepy.py -i VisualStudio.VCProjectEngine.10.0
VCProjectEngineLibrary
{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}, lcid=0, major=10, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}', 0, 10, 0)
makepy.py -i
注: で指定された CLSID が に一致するVisualStudio.VCProjectEngine.8.0
が、VisualStudio.VCProjectEngine.10.0
(レジストリに が表示されている場合{4547a58d-fc1c-4502-84fa-0163ee766635}
)には一致しないことに気付きました。
ただし、タプルを調整してもVisualStudio.VCProjectEngine.10.0
、('{4547a58d-fc1c-4502-84fa-0163ee766635}', 0, 10, 0)
例外には役立ちません。
このエラーは、Visual Studio 2010 以降で発生しているようです。によって与えられた値で ProgID としてVisualStudio.VCProjectEngine.11.0
も試しましたが、エラーは同様でした:VisualStudio.VCProjectEngine.12.0
makepy.py -i
Error for VisualStudio.VCProjectEngine.11.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Error for VisualStudio.VCProjectEngine.10.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Error for VisualStudio.VCProjectEngine.12.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u'One or more errors occurred.', None, 0, -2146233088), None)