pythoncom39.dll script engine broken due to python39.dll not found
Failing setup:
- 64bit Python 3.9 installed to
C:\Users\<user>\AppData\Local\Programs\Python\Python39 pywin32-301.win-amd64-py3.9installed from command prompt with admin privileges.
PyWin32 will then install & register C:\Users\<user>\AppData\Local\Programs\Python\Python39\Lib\site-packages\pywin32_system32\pythoncom39.dll as Python scripting engine. However, this DLL won't load when trying to instantiate the scripting engine from unrelated C++ or C# code due to the dependent python39.dll not being found by Windows.
Minimal C++ reproducer:
#include <Windows.h>
#include <activscp.h>
int main (int argc, char* argv[]) {
CoInitialize(0);
CLSID clsid = {};
HRESULT hres = CLSIDFromProgID(L"Python", &clsid);
if (FAILED(hres))
return -1;
IActiveScript* engine = nullptr;
hres = CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, IID_IActiveScript, reinterpret_cast<void**>(&engine));
if (FAILED(hres)) // fails with ERROR_MOD_NOT_FOUND The specified module could not be found.
return -2;
return 0;
}
Suggested fix:
Install pythoncom39.dll to the same folder as python39.dll so that Windows is able to detect & load the dependent DLL.
Sorry for the delay here:
* `pywin32-301.win-amd64-py3.9` installed from command prompt with admin privileges.
...
Install pythoncom39.dll to the same folder as python39.dll so that Windows is able to detect & load the dependent DLL.
All the code from here is trying to do exactly that. It would be great to know if the file is copied next to python39.dll, but we still register COM objects against the wrong dll, or that copy code didn't run, so the pywin32_system32 ones are the only ones you have?
Screenshot of my pywin32_system32 and Python39 root folders:

As you can see, then pythoncom39.dll and python39.dll are not in the same folders. I'm using pywin32 version 301.
I've just tested, and the same problem seem to occur with both Python 3.8 and 3.9.
The post install script probably copied it into your system32 directory - can you check if it is there, and if so, whether a copy of pythonXX.dll is also there?
My System32 folder seem to contain pythoncom39.dll but no python39.dll:

It seems like the version in C:\Users\<user>\AppData\Local\Programs\Python\Python39\Lib\site-packages\pywin32_system32 is the one that is registered during install:
