Giter VIP home page Giter VIP logo

python-for-lazarus's People

Contributors

alexey-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-for-lazarus's Issues

Error installing from Lazarus Online Package Manager

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

image

Error when importing package psycopg2

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.

Pull request

Hello Alexey,

I would like to make Pull request to you Is there any prohibition permission to make it?

Lazarus crashes while delete components

Add PythonEngine PythonInputOutput Python Module.

Connect PythonInputOutput with PythonEngine.

Select all coimponents with mouse . Press Del. button on keyboard.

Lazarus crashes.

Regression in master branch

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!

LongInt size on non-Windows 64bit platforms

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.

Support VarPyth.pas

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.

No rule to make target 'cleanide ide'. Stop.

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?

python310.dll: some functions have been removed.

Из python 3.10 удалили некоторые функции, поэтому TDynamicDll.Import() бросает исключение.
Вот чего не хватает:
PyOS_InitInterrupts()
PyLong_FromUnicode()
PyParser_SimpleParseStringFlags()
PyParser_SimpleParseStringFlagsFilename()
PyParser_SimpleParseFileFlags()
PyNode_Compile()
PyNode_Free()

Command Line Sample

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.

Unfreed memory blocks: 80

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?
Untitled

Different Python versions etc.

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.

TPythonEngine.Destroy

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;

Invalid syntax when compiling the package

Can not install the latest version due to a compile error. Seem because this line is invalid syntax

private class threadvar

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

vcruntime for Windows

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}

fix library path for macOS for demos

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.

Missing functions

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?

Python 2.7 support on Ubuntu 18.04

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.

Availability of the latest version on Lazarus Online Package manager and differences with Python4Delphi

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!

Questions about Linux

Sorry to ask a questions via the issue tracker.

  • Where is typically the libpythonx.y.so located?
  • In Linux do you normally have to specify a path to the python so file?

Thanks!

demo project fails to compile

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';

  1. If I change string to UnicodeString it still fails to compile.
  2. If I remove the funny looking (Unicode) characters of this line I can compile the project.
  3. If I change the line to Unicode 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.

Demo01-06

Thanks Alex, You can add also demo01, it was also changed. Ok I will remove project1. I let you know.

How to pass a callback function from Pascal as a parameter to a Python function?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.