Delphi P4D Error 87: Could not open Dll "python33.dll"

好记性不如乱笔头,记下来总是好的。。。
回复
BG6RSH
帖子: 132
注册时间: 周日 6月 23, 2019 12:00 pm

Delphi P4D Error 87: Could not open Dll "python33.dll"

帖子 BG6RSH »

https://github.com/pyscripter/python4de ... dingPython

Python for Delphi 如何在 Windows 中找到您的 Python 发行版
要使用Python for Delphi,您需要下载并安装python。有许多不同的python发行版,最常见的是来自 www.python.org 或用于数据分析的Anaconda发行版。

已注册与未注册
在 Windows 中安装 Python 时,可以选择为所有用户或当前用户注册它。注册涉及向注册表写入有关安装位置、帮助文件的名称和位置等信息。

设置 PythonEngine 的属性
如果要使用已安装的最新注册的 Python 版本
将“使用上次已知版本”属性设置为 True
如果需要特定的注册版本,则需要设置以下属性:
DLLName 例如 python38.dll
注册表版本,例如 3.8
将“使用上一个已知版本”属性设置为 False
如果要使用特定的未注册版本,请设置以下属性
DLLName 例如 python38.dll
注册表版本,例如 3.8
将“使用上一个已知版本”属性设置为 False
将 DLLPath 设置为 DLL 所在的路径
将自动加载属性设置为 False
将以下语句添加到 PythonEngine OnBeforeLoad 事件处理程序中,假设 PythonEngine 是组件的名称
PythonEngine.SetPythonHome('your python installation directory')
将以下语句添加到 FormCreate 处理程序:
PythonEngine.LoadDll;

笔记:

32 位 Delphi 应用程序仅适用于 32 位版本的 Python,64 位 Delphi 应用程序仅适用于 64 位版本的 Python。
Anaconda 发行版要求你调用 SetPythonHome,即使它们已注册。
使用 PythonVersions 单元
PythonVersion 单元可以帮助正确查找和加载您想要的 python 版本。它处理各种复杂性,例如注册/未注册版本,Anaconda发行版和虚拟环境。要使用它,请将 PythonEngine 的 Autoload 属性设置为 False,然后在 FormCreate load python 中,如下所示:
  1.   var PythonVersion: TPythonVersion
  2.  
  3.   if GetRegisteredPythonVersion(SysVersion, PythonVersion) then
  4.   or
  5.   if PythonVersionFromPath(Path, PythonVersion) then
  6.   begin
  7.     PythonVersion.AssignTo(PythonEngine)
  8.     PythonEngine.LoadDLL
  9.   end
  10.  
以下是 TPythonVersion.AssignTo 过程:
  1. procedure TPythonVersion.AssignTo(PythonEngine: TPersistent);
  2. begin
  3.   if PythonEngine is TPythonEngine then
  4.   begin
  5.     TPythonEngine(PythonEngine).UseLastKnownVersion := False;
  6.     TPythonEngine(PythonEngine).RegVersion := SysVersion;
  7.     TPythonEngine(PythonEngine).DllName := DLLName;
  8.     TPythonEngine(PythonEngine).DllPath := DLLPath;
  9.     TPythonEngine(PythonEngine).APIVersion := ApiVersion;
  10.     if Is_venv then begin
  11.       TPythonEngine(PythonEngine).VenvPythonExe := PythonExecutable;
  12.       TPythonEngine(PythonEngine).SetPythonHome(DLLPath);
  13.     end else if not IsRegistered or Is_conda then
  14.       {
  15.          Not sure why but PythonHome needs to be set even for
  16.          registered conda distributions
  17.          Note also that for conda distributions to work properly,
  18.          you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath]
  19.          to your Windows path if it is not there already.
  20.       }
  21.       TPythonEngine(PythonEngine).SetPythonHome(InstallPath);
  22.   end;
  23. end;
回复