Alexey-T / Python-for-Lazarus

Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
MIT License
127 stars 42 forks source link

vcruntime for Windows #35

Closed neurolabusc closed 3 years ago

neurolabusc commented 3 years ago

At the moment, Python-for-Lazarus running on Windows fails to load the Python3*.dll if the computer does not have the file vcruntime140.dll in the system's path. I notice that CudaText includes this dll.

I would suggest including this library at the same location as the Python3*.dll and explicitly loading it by changing Line 2911

    {$ifdef windows}
    S := GetDllPath+'vcruntime140.dll';
    FDLLHandle := Windows.LoadLibrary(PChar(S));
    S := GetDllPath+DllName;
    FDLLHandle := Windows.LoadLibrary(PChar(S));
    {$else}
Alexey-T commented 3 years ago

I dont like the idea 'to explicitly load it', it's bad practice. Better to add the info somewhere.

neurolabusc commented 3 years ago

An alternative would be to add the path of the Python3*.dll to the Windows DLL search path using SetDllDirectoryA, that way Windows can find and load the vcruntime DLL if needed:

{$ifdef windows}
function  SetDllDirectory(lpPathName: LPCTSTR):LongBool; stdcall; external 'kernel32.dll' name 'SetDllDirectoryA'; //uses add windows,sysutils,
{$endif}
...
SetDllDirectory(PChar(GetDllPath));
Alexey-T commented 3 years ago

It''s not needed for Py4Lazarus, it is the code for final app. so add it in your app.

neurolabusc commented 3 years ago

The Python-for-Lazarus demos_lazarus applications will not run on computers that do not have vcruntime in their system path. The error message provided does not provide the user or developer with any feedback for diagnosis. I would suggest adding it to Python-for-Lazarus, but alternatively you could add it to the demo apps.

I have added the SetDllDirectory solution to the PythonPascalBridge repository. This is an alternative to Python-for-Lazarus but allows static linking of Python into Linux and macOS executables.

Alexey-T commented 3 years ago

But that VS runtime is present, because it’s required for python DLL.