python - 找到正确的 python4delphi Tpythonengine 参数
问题描述
从这里python 4 delphi使用 Tpythonengine 时,由于这些计算机上的 python 配置不同,我无法让我的代码 *.exe 在不同的系统上运行。按照 示例代码的思路,我通过一个*.ini文件,完成了所有python4delphi-TpythonEngine参数的设置。
只有一个在 WINDOWS 操作系统上设置 python4Delphi 的教程(在 WINDOWS 下配置 ,但不适用于 LINUX。
有人可以帮助为最新的 UBUNTU、CENTOS、LINUX MX 发行版提供正确的参数。
最重要的代码部分在这里
FPythonEngine := TPythonEngine.Create(nil);
FPythonDelphiVar := TPythonDelphiVar.Create(nil);
try
FPythonEngineConfig.SetPythonengineValues(FPythonEngine);
FPythonEngine.IO := PythonGUIInputOutput;
FPythonDelphiVar.VarName := 'Properties';
FPythonDelphiVar.Module := '__main__';
FPythonDelphiVar.OnExtGetData := PropertiesExtGetData;
FPythonDelphiVar.OnExtSetData := PropertiesExtSetData;
FPythonDelphiVar.OnChange := PropertiesChange;
FPythonDelphiVar.Engine := FPythonEngine;
FPythonEngine.Loaddll;
and the transfer of the in ini -file parameters to the Tpythonengine
procedure TPythonEngineConfig.SetPythonengineValues(PythonEngine
: TPythonEngine);
var
FPyVersions: TPythonVersions;
begin
///
/// convert this https://github.com/pyscripter/python4delphi/wiki/FindingPython
/// into a small automatic setting of parameter
///
PythonEngine.UseLastKnownVersion := Self.UseLastKnownVersion;
if Self.UseLastKnownVersion then
begin
{$IFDEF MSWINDOWS}
FPyVersions := GetRegisteredPythonVersions;
FPyVersions[0].AssignTo(PythonEngine);
{$ENDIF}
{$IFDEF LINUX}
/// not supported on LINUX
/// https://en.delphipraxis.net/topic/4700-getregisteredpythonversions-for-linux/
{$ENDIF}
end
else
begin
PythonEngine.APIVersion := self.APIVersion ;
PythonEngine.DllName := Self.DllName;
PythonEngine.DllPath := Self.DllPath;
PythonEngine.AutoFinalize := Self.AutoFinalize;
PythonEngine.AutoLoad := Self.AutoLoad;
PythonEngine.AutoUnload := Self.AutoUnload;
PythonEngine.RedirectIO := Self.RedirectIO;
PythonEngine.UseWindowsConsole := Self.UseWindowsConsole;
PythonEngine.RegVersion := Self.RegVersion;
end;
end;
解决方案
推荐阅读
- excel - 宏,连续擦除数据(锁定单元格在混合位置)
- cmake - 我可以将 CMakeLists.txt(s) 放在单独的文件夹中吗?
- dart - 在 Flutter 应用程序中将辅助隔离中的地理定位作为后台任务
- python - 无法通过 JSON 文件中的第一个字典
- javascript - 为什么mysql数据库信息不会传递给express.js函数?
- php - 改造不返回 ETag 和 Last-Modified
- android - 以编程方式设置 TabLayout 项目标题
- python - 在 python 中读取 NetCDF 文件
- maven - Cucumber+Maven+TestNG-->即使在构建成功后,控制台输出也会显示为 TestRun as 0
- python-3.x - 将“预压缩”列表值转换为整数