python4delphi
python4delphi copied to clipboard
"No Python Engine was created" with Python 3.10
Hi!
I've being able to use Python4delphi with no issues on Python 3.7 32 bits that we use on most computers and servers. Even ISAPI web server applications are working well (to use Jinja in Delphi, great lib BTW!).
But when trying to use in a new installation of Python 3.10 straight from Python's official website, it returns the "No Python Engine was created" error message, plus a "Exception EInvalidPointer in Module... Invalid pointer operation".
I compiled as 64 bits application, as this Python version is 64 bits (tried 32 bits compilation, same result). I'm using Delphi 10.3, and reinstalled Python4delphi from last installer available for D10.3- (API version 1013). Path is configured for Python folder and sub-folder Scripts.
I read all instructions in the "Finding Python" page (here), and included this code in a very simple "hello world" application (that uses no Python library):
procedure TForm1.FormCreate(Sender: TObject);
var PythonVersion: TPythonVersion;
begin
PythonVersion.AssignTo(PythonEngine1);
PythonEngine1.LoadDLL;
end;
procedure TForm1.AssignTo(PythonEngine: TPersistent);
begin
if PythonEngine is TPythonEngine then
begin
TPythonEngine(PythonEngine).UseLastKnownVersion := False;
TPythonEngine(PythonEngine).RegVersion := '3.10';
TPythonEngine(PythonEngine).DllName := 'python310.dll';
TPythonEngine(PythonEngine).DllPath := 'C:\Program Files\Python310\';
TPythonEngine(PythonEngine).AutoLoad := False;
TPythonEngine(PythonEngine).SetPythonHome('C:\Program Files\Python310\');
end;
end;
procedure TForm1.PythonEngine1BeforeLoad(Sender: TObject);
begin
PythonEngine1.SetPythonHome('C:\Program Files\Python310\');
end;
The 32 bits version worked straight on several machines I tested with Python 3.7 and detected it automatically. Running the 64 bits version on Python 32 bits returns the same error (as expected).
I found a very old issue reported here about the same error message, but closed as a fixed issue. Is there some new issue related to Python 3.10?
P4D works fine with python 3.10 here (and with other users). So you have python 3.10 64 bits installed and registered. Does the Demo01 (which has UseLastKnownVersion = True) run?
Hi Kiriakos,
Thank you very much for the reply!
Is the version of app we can create with python4delphi tied to the bittage of Python present in the machine COMPILING the app?
I know that bittage is relevant, as it is clear on your presentations (just watched you on Coding Boot Camp 2022), but I thought that it would make difference at RUN TIME only, not at compile time. So, in a machine with 32 bits Python I should be able to compile the 64 bits app, that of course would not be able to run on that same machine, but should run in other machines having 64 bits Python. But it seems it does not happen.
Actually I'm not even being able to compile with crossed bittage. In a machine with Delphi 10.3 and 32 bits Python 3.7.2 I can compile your Demo01 for Win32, but trying to compile for Win64 I get this error: [dcc64 Fatal Error] Demo01.dpr(7): F2048 Bad unit format: Unit1.dcu - Expected version: 33.0, Windows Unicode(x64) Found version: 33.0, Windows Unicode(x86). And, in a brand new installation of Delphi 3.11.1, Windows 11 and 64 bits Python 3.10.6, I can compile for 64 bits, but trying to compile for Win32 I get almost same error: "[dcc32 Fatal Error] Demo01.dpr(7): F2048 Bad unit format: Unit1.dcu - Expected version: 35.0, Windows Unicode(x86) Found version: 35.0, Windows Unicode(x64).
So it seems that we can COMPILE only for the same bittage of installed Python.
_A courious fact is that if I try to run the 32 bits Demo01 on computer with Python 64 bits, I get the error 'Error 126: Could not open Dll python34.dll', and when running the 64 bits Demo01 on a computer with Python 32 bits, I have the error 'Error 87: Could not open Dll python34.dll'. Different error codes, same Dll. What Dll is this? (errors are expected on these tests, of course)_
At the end, I'm being able to compile python4delphi for 64 bits in one computer and for 32 bits in another, according their installed Python...
Thanks and regards!
[dcc64 Fatal Error] Demo01.dpr(7): F2048 Bad unit format: Unit1.dcu - Expected version: 33.0, Windows Unicode(x64) Found version: 33.0, Windows Unicode(x86).
You need to build your project not just compile.
Hi,
Thanks a lot for the very fast reply!
It worked! :-D
Actually only after I updated python4delphi in the Delphi 3.10/Python 32 bits computer to python4delphi version 3.11 (the one with folders fmx/vcl/lcl within source folder), I could compile my own tests in both computers, and both "bitages" on each, all running on respective Python, regardless the Python bitage or Delphi version at the compiling machine. But that message above remained on your Demo01. But building instead only compiling solved it as well!
Thank you!
PS: OFF TOPIC: I remember some comment in one of your presentations regarding multitasking with Python. One of the goals I'm trying is to do an webserver app, CGI (.exe) or ISAPI (.dll) using Python and Delphi WebBroker. Should it work? Several CGI instances may run at same time, each one calling Python, but in separate processes, so probably it will work. But ISAPI may have several threads within the same process, each one calling Python...
PS: OFF TOPIC: I remember some comment in one of your presentations regarding multitasking with Python. One of the goals I'm trying is to do an webserver app, CGI (.exe) or ISAPI (.dll) using Python and Delphi WebBroker. Should it work? Several CGI instances may run at same time, each one calling Python, but in separate processes, so probably it will work. But ISAPI may have several threads within the same process, each one calling Python...
Multi-tasking and multi-processing is hard even without using python. Everything is possible if you do it right. Your question cannot be answered with a simple yes or no.