alexey-t / python-for-lazarus Goto Github PK
View Code? Open in Web Editor NEWFork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
License: MIT License
Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
License: MIT License
I tried to install it in Lazarus from the online package manager, but I got the following error during install...
I'm testing with Lazarus on RaspberryPi 4
Compile package python4lazarus_package 1.4: Exit code 1, Errors: 2, Warnings: 1, Hints: 12
.
.
.
PythonEngine.pas(2617,17) Error: Procedure or Function expected
PythonEngine.pas(2617,17) Fatal: Syntax error, "identifier" expected but "THREADVAR" found
Hi.
Hi. I can run simple Python commands from the test program
I have a Python script that connects to a Postgsql DB. The scrip works fine when I run it in Python, but when I embed it in Lazarus I get this error.
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: /usr/local/lib/python3.7/dist-packages/psycopg2/_psycopg.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: PyExc_SystemError
[FORMS.PP] ExceptionOccurred
Sender=EPyImportError
Exception=ImportError: /usr/local/lib/python3.7/dist-packages/psycopg2/_psycopg.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: PyExc_SystemError
Stack trace:
$00402708 TPYTHONENGINE__RAISEERROR, line 5452 of ./Sources/Core/PythonEngine.pas
$00407CD0 TPYTHONENGINE__CHECKERROR, line 6459 of ./Sources/Core/PythonEngine.pas
$00401ECC TPYTHONENGINE__RUN_COMMANDASOBJECTWITHDICT, line 5259 of ./Sources/Core/PythonEngine.pas
$00401D18 TPYTHONENGINE__RUN_COMMANDASOBJECT, line 5225 of ./Sources/Core/PythonEngine.pas
$00401C68 TPYTHONENGINE__EXECSTRING, line 5210 of ./Sources/Core/PythonEngine.pas
$0007C590 TEST_CODE_$$_init$, line 51 of test_code.pas
$0004B350
Exception at 00402708: EPyImportError:
ImportError: /usr/local/lib/python3.7/dist-packages/psycopg2/_psycopg.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: PyExc_SystemError.
Hello Alexey,
I would like to make Pull request to you Is there any prohibition permission to make it?
Add PythonEngine PythonInputOutput Python Module.
Connect PythonInputOutput with PythonEngine.
Select all coimponents with mouse . Press Del. button on keyboard.
Lazarus crashes.
I am using Lazarus trunk (SVN 62843) and fpc (3.0.4+dfsg-23 [2019/11/25]) with Ubuntu 20.04 daily. I can install and run the current release (2019.12.26) of Python-for-Lazarus just fine. The only change I made to the Demo is to set the location of my Python library:
cPyLibraryLinux = '/usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so';
However, if I uninstall the lpk and git clone and install the latest master release of Python-for-Lazarus, things do not work as expected. The example demos all fail:
Error: Could not open Dll "libpython3.8.so"
Python could not be properly initialized. We must quit.
Since the demos have changes, I also recompiled the demo project from the 2019.12.26 release, and it also fails to run when the latest master .lpk is installed.
Conversely, if I install the stable release (2019.12.26) .lpk, I am able to successfully compile and run the demo files included in the more recent master.
There seems to be some regression with the latest master. Thanks again for your support of this terrific package!
In FPC LongInt is always 4bytes.
In Delphi LongInt is 4bytes on Windows (32 and 64bits) but 8 bytes on MacOS and Linux 64bits.
Same is true about Python and gcc's long type.
As it stands FPC programs will fail on MacOS and Linux 64bits when they use Python interface functions that have LongInt or LongWord arguments. (Search for LongInt in PythonEngine.pas).
LongInt should be replaced with a typedef that behaves as Delphi and Python.
It appears that one of the important fpc bugs that was restricting the usefulness of VarPyth in Lazarus has been fixed.
See
https://bugs.freepascal.org/view.php?id=20849
https://bugs.freepascal.org/view.php?id=38429
It appears to have been fixed in Revision 48477. Do you have any clue as to when this revision will be included in Lazarus?
VarPyth is great. It makes using python in Pascal so much easier. Check https://github.com/pyscripter/python4delphi/blob/master/Tests/VarPythTest.pas to see what can be done with VarPyth. It would be nice to support VarPyth in your repo .
Also it would be nice to add the unit tests to your repo after adapting them for fpc, so we can easily test the parity between Delphi and Lazarus.
This is a question about P4D.
P4D fails with fpc and MacOS, while your fork works. Please see https://en.delphipraxis.net/topic/4131-installingexecuting-python4delphi-app-on-macos-lazarus-could-not-map-symbol-p%EF%BB%BFy_debugflag%EF%BB%BF%EF%BB%BF%EF%BB%BF
I compared the source code and could not see any significant difference in Import and MapDLL. Any clues why P4D fails and P4L works?
Thanks!
I am trying to include this package in lazarus 2.0.2, via:
./lazbuild -B --lazarusdir="." --pcp="../lazarus-package-config" --build-ide=Gentoo --add-package ../Python-for-Lazarus-11110be6034c7e39daa2cf7154ad04bba0e1cb04/python4lazarus/python4lazarus_package.lpk
and I get No rule to make target 'cleanide ide'. Stop.
. Here is the full build.log.
Any idea what I can do?
Из python 3.10 удалили некоторые функции, поэтому TDynamicDll.Import() бросает исключение.
Вот чего не хватает:
PyOS_InitInterrupts()
PyLong_FromUnicode()
PyParser_SimpleParseStringFlags()
PyParser_SimpleParseStringFlagsFilename()
PyParser_SimpleParseFileFlags()
PyNode_Compile()
PyNode_Free()
Hi.
Do you have a sample where there is no forms but just command line app. I want to wrap Python code inside Lazarus so users can not read the code. But all samples use GUI forms.
Hi
Is it possible to using python with virtual environment ?
Thanks
Thank you for creating python4Lazarus. I have succesfully installed it with lazarus ver 1.2.6 and able to run python script with no major issue.
However, I noticed that there is always some unfreed memory block whenever I use tpythonDelphivar in my apps. This error even occurs when there are only a TpythoneEngine and pythonDelphiVer in a blank form (without addtional code). What can I do to free all the memory?
Three related questions:
Am I correct in assuming that the Lazarus Demo projects haven't yet been converted?
Am I correct in noting that the library name has (at present) to be hardcoded in e.g. Python_Console/FormMain.pas?
Am I correct from looking at the code that the Python version definitions in Definition.Inc are unused?
The last one is the result of my casually trying Python 2.7.
Could you please add a license to this project? Since this is a fork of python4delphi, I presume it maintains the MIT License. I realize that files like PythonEngine.pas include a license, but it would be nice to have an explicit license at the top level.
Any plan to support Apple Silicon arm64 machines too with newest Lazarus build (2.2) ?
Question: Is it really necessary to do it differently in fpc than delphi?
destructor TPythonEngine.Destroy;
begin
LocalVars := nil;
GlobalVars := nil;
Destroying;
Finalize;
{$IFDEF FPC}
inherited;
{$ENDIF} // Free our objects
FClients.Free;
FInitScript.Free;
FTraceback.Free;
FLock.Free;
{$IFNDEF FPC}
inherited;
{$ENDIF}
end;
Can not install the latest version due to a compile error. Seem because this line is invalid syntax
I update full compiler error log:
Compile package python4lazarus_package 1.4: Exit code 1, Errors: 2, Hints: 12
...(Hints)...
PythonEngine.pas(2617,17) Error: Procedure or Function expected
PythonEngine.pas(2617,17) Fatal: Syntax error, "identifier" expected but "THREADVAR" found
PS: FPC version 3.04, Lazarus version 2.0.4
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}
moving to an Intel Mac where
/Library/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
exists, and where I use this as the DLL, the sample project
/demos_lazarus/Python_Console
compiles and launches, but never executes any Python code, even a simple print(3+2). Would it be possible to have at least one working Lazarus demo. It is strange that some of the demos in this repository seem to require the a package from a different repository (P4DLaz). I was also unable to get P4Dlaz to install.
Hello,
The 2020.07.31 included many functions that I used that have been removed from the 2020.10.23 release. Specifically: PyString_AsAnsiString, PyString_FromString, PyInt_FromLong. Was there a reason for their removal? What alternative functions can be used with the new code?
This issue is related to this post, e.g. issues with Python 2.7 on Linux but not MacOS.
I downloaded the latest Python-4-Lazarus (with 64 commits) and opened on my Ubuntu 18.04 system with Lazarus 2.1.0 SVN 62040M GTK2 and FPC 3.0.4. I opened the demo_lazarus project and attempted to compile. Once I fix Py_s1 the demo runs fine if I set
cPyLibraryLinux = '/usr/lib/x86_64-linux-gnu/libpython3.6m.so';
however, if I set this to
cPyLibraryLinux = '/usr/lib/x86_64-linux-gnu/libpython2.7.so';
(which also exists on my computer), the program crashes. I added a conditional for Python3 in the PythonEngine.pas:
if IsPython3000 then
PyUnicode_FromWideChar :=Import(AnsiString...
The program seems to run (though at launch it reports Error: could not find symbol "PyUnicodeUCS2_AsWideChar"
), and I can run a basic Python script, but when I attempt to close the program it crashes.
The crash is as follows...
Error: could not find symbol "PyUnicodeUCS2_AsWideChar"
[FORMS.PP] ExceptionOccurred
Sender=EAccessViolation
Exception=Access violation
Stack trace:
$0000000000000000
$0000000000796514 line 4665 of Sources/Core/PythonEngine.pas
$00000000004A484D
$0000000000552F19 line 5130 of include/control.inc
$0000000000540FB8 line 6645 of include/wincontrol.inc
$00000000005557EF line 40 of include/customcontrol.inc
$0000000000447CBF line 316 of include/scrollingwincontrol.inc
$0000000000449231 line 131 of include/customform.inc
$0000000000430BD0
$0000000000444BF6 line 1937 of forms.pp
$00000000004352B9
Exception at 0000000000000000: EAccessViolation:
Access violation.
Hello,
If I try to install the package through the Online Package Manager built-in in Lazarus, I see I can install the version 1.4.0, while here you use a different release number. Are the one there synced with this repo?
What are the differences between Python4Delphi and Python4Lazarus? In the wiki page of Python4Lazarus you stated the P4D supports FPC/Lazarus too. What is the latest one for Lazarus/MacOS ?
thank you!
Sorry to ask a questions via the issue tracker.
Thanks!
Does this happen with your fork?
I downloaded the latest Python-4-Lazarus (with 64 commits) and opened on my Ubuntu 18.04 system with Lazarus 2.1.0 SVN 62040M GTK2 and FPC 3.0.4. I opened the demo_lazarus project and attempted to compile. The function FormMain.pas Py_s1 generates the error
formmain.pas(58,16) Error: UTF-8 code greater than 65535 found
This line looks like this
S0: string = 'begin.𠏽𠏽𠏽𠏽𠏽.end';
S0: UnicodeString = '╩';
is compiles.Not sure if this is simply a problem with Github encoding of text files or not.
Thanks for supporting this terrific project.
Thanks Alex, You can add also demo01, it was also changed. Ok I will remove project1. I let you know.
Hi,
I have tried several approaches to pass a Delphi callback function to be used by Python, but the functions are not being called.
`
procedure CallbackFunc(args: Variant);
begin
Form1.Memo1.Lines.add('111');
// ...
end;
callback:=PythonEngine1.PyCFunction_NewEx(@CallbackFunc, nil,nil);
PythonEngine1.Py_INCREF(callback);
//client.subscribe_whole_quote(NewPythonDict,TVarProc(cb));
//codelist := VarPythonCreate(['SZ']);
codelist := PythonEngine1.PyList_New(1);
PythonEngine1.PyList_SetItem(codelist, 0, PythonEngine1.PyUnicode_FromString('110072.SH'));
argsTuple := PythonEngine1.PyTuple_New(2);
PythonEngine1.PyTuple_SetItem(argsTuple, 0, codelist);
PythonEngine1.PyTuple_SetItem(argsTuple, 1, callback);
ss :=GetPythonEngine.EvalPyFunction(ExtractPythonObjectFrom( client.subscribe_whole_quote ), argsTuple); `
in the code subscribe_whole_quote is a python function have 2 parms, 1st is a list, and 2d is the callback function, when I called the subscribe_whole_quote it returned success, but never call the callback function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.