Free components that wrap up Python into Delphi and Lazarus (FPC)

Overview

P4D Logo

Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi and Lazarus (FPC). They let you easily execute Python scripts, create new Python modules and new Python types. You can create Python extensions as DLLs and much more. P4D provides different levels of functionality:

  • Low-level access to the python API
  • High-level bi-directional interaction with Python
  • Access to Python objects using Delphi custom variants (VarPyth.pas)
  • Wrapping of Delphi objects for use in python scripts using RTTI (WrapDelphi.pas)
  • Creating python extension modules with Delphi classes and functions

P4D makes it very easy to use python as a scripting language for Delphi applications. It also comes with an extensive range of demos and tutorials.

How to use Python4Delphi

The best way to learn about how to use Python for Delphi is to try the extensive range of demos available. Also studying the unit tests for VarPyth and WrapDelphi can help understand what is possible with these two units.

Wiki topics

Learn about Python for Delphi

Support forum

Visit the support forum to ask questions and discuss P4D related issues.

License

The project is licensed under the MIT license.

Comments
  • Update all Demos to Python 3

    Update all Demos to Python 3

    Python 2 has reached the end of its life, and we can assume that most of the users will have installed python 3. Most of the demos use python 2 print statements and some may use other python 2 idioms.

    To facilitate experimentation and learning with the demos they should be converted to python 3.

    Also all forms should be changed to text format and the old application icon replaced with the default icon.

    help wanted Fixed good first issue 
    opened by pyscripter 30
  • Need help for Python error: wrong char code outside of range [0..$10ffff]

    Need help for Python error: wrong char code outside of range [0..$10ffff]

    I use this fork https://github.com/alexey-t/python-for-lazarus In the folder demo_lazarus I have a demo, which shows the problem. I cannot test this on Delphi (no Delphi here, I use Linux Ubuntu 18.x x64, Python 3.7).

    • i run the demo
    • demo provides Py module "demo" with function "s1". So i test it.
    • in demo console, i enter
    import demo
    =demo.s1()
    

    and have this error. Screenshot from 2019-10-10 13-04-15

    This is from Unicode string with high values:

    function Py_s1(Self, Args : PPyObject): PPyObject; cdecl;
    const
      S0: string = 'begin.𠏽𠏽𠏽𠏽𠏽.end';
    begin
      with GetPythonEngine do
        Result:= PyString_FromString(PChar(S0));
    end;
    

    Can you repro this on Delphi?

    opened by Alexey-T 27
  • PyNumberMethods record is incorrect for Python 3.x

    PyNumberMethods record is incorrect for Python 3.x

    The PyNumberMethods record was designed for Python 2.x and still contains nb_divide, nb_coerce, nb_oct, nb_hex and nb_inplace_divide. On the other hand, it lacks nb_index, nb_matrix_multiply and nb_inplace_matrix_multiply. Also, nb_nonzero was renamed as nb_bool and nb_long as nb_reserved. Finally, it has a typo for nb_substract, which should read nb_subtract.

    As a result, for Python 3.x e.g. TPythonType_NbPower() will be called when TPythonType_NbNegative() is intended.

    Fixed 
    opened by LennertP 25
  • xe2 bpl installation problem , need help

    xe2 bpl installation problem , need help

    Windows10 Delphi Xe2 update 4 libarary path is added while installation Python_D150.bpl IDE raise Error: [DCC Error] WrapDelphi.pas(2789): E2003 Undeclared identifier: 'TypeData' and point to Error line: WarpDelphi.pas line 278: if (RttiParam.ParamType = nil) or (RttiParam.ParamType.Handle = nil) or (RttiParam.ParamType.Handle.TypeData = nil) then Exit;

    I check out the Unit Sytem.Typinfo found a Strange place:

    PPTypeInfo = ^PTypeInfo; PTypeInfo = ^TTypeInfo; TTypeInfo = record Kind: TTypeKind; Name: ShortString; {TypeData: TTypeData} end;

    the TypeData section is be marked with a curly bracket in Delphi Xe2 !!! I'm not sure if it makes trouble.

    opened by mitchellhu 19
  • Python3.7 not able to identified.

    Python3.7 not able to identified.

    I tested code at Ubuntu 19.04 with Python 3.7 and library

    /usr/lib/x86_64-linux-gnu/libpython3.7m.so

    I changed PythonEngine.pas file to

    
    {$IFDEF _so_files}
      PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
        (
        (DllName: 'libpython2.7.so'; RegVersion: '2.7'; APIVersion: 1013),
        (DllName: 'libpython3.2.so'; RegVersion: '3.2'; APIVersion: 1013),
        (DllName: 'libpython3.3.so'; RegVersion: '3.3'; APIVersion: 1013),
        (DllName: 'libpython3.4.so'; RegVersion: '3.4'; APIVersion: 1013),
        (DllName: 'libpython3.5.so'; RegVersion: '3.5'; APIVersion: 1013),
        (DllName: 'libpython3.6.so'; RegVersion: '3.6'; APIVersion: 1013),
        (DllName: 'libpython3.7m.so'; RegVersion: '3.7'; APIVersion: 1013),
        (DllName: 'libpython3.8.so'; RegVersion: '3.8'; APIVersion: 1013)
        ); 
    

    Then the python3.7 was recognized but at least not correctly initialized. at line 3057

    
          // set the argv list of the sys module with the application arguments
          PySys_SetArgv3000( argc + 1, wargv );
    

    With error message:

    Project Project1 raised exception class 'External: SIGABRT'. In file '../sysdeps/unix/sysv/linux/raise.c' at line 50

    Currently is recognized only Python 2.7. Maybe you will know how to fix it.

    opened by mamin27 16
  • updated MethodCallback unit: now it don't work on FPC ARM64

    updated MethodCallback unit: now it don't work on FPC ARM64

    I sync'ed this unit (in python4lazarus) and now CudaText ARM64 don't work. it shows py error on start. ValueError: module functions cannot set METH_CLASS or METH_STATIC

    I am comparing the new unit with old one (in Python4Lazarus before sync with you). old unit did not have all variants of function GetCallBack. attached this old unit. MethodCallBack.zip

    can you please make sure FPC ARM64 works now?

    My device: Raspberry Pi-3, OS: Manjaro ARM.

    opened by Alexey-T 15
  • Script working now not working

    Script working now not working

    Hello,

    I hope I am in the right place for this question. I apologize if I should be asking this somewhere else. I did post this question on the general Lazarus forum but did not get any feedback.

    I am using Python for Lazarus in an application to communicate with a few different lab instruments.

    I have a Lazarus application that was running well using the NI-Visa library for python. It suddenly stopped working and is now throwing an error:

    AttributeError: module 'visa' has no attribute 'ResourceManager'

    The odd part is that the same python code runs fine from IDLE or python directly? I am struggling to find any information on how P4L or P4D interacts with python and where this problem could be coming from. I would think they would use the same python module?

    I did get some good feedback from python visa forum but I think the visa and python side check out as ok because it is running in python itself. This seems to be something specific to the Lazarus side?

    Simple python script that returns error: import visa

    from ThorlabsPM100 import ThorlabsPM100 rm = visa.ResourceManager()

    Other python scripts seem to run fine from the same Lazarus application.

    Any information would be greatly appreciated.

    opened by mcinquino 15
  • delphi 10.4 installation fails

    delphi 10.4 installation fails

    Downloaded latest files from github. Added library path to source.Tried installing on newly installed delphi 10.4 . Build fails because cannot find Pythonguiinputoutput.pas which is in the vcl subfolder. move this file to the source folder and remove vcl prefix. then it fails on not finding designide. add the path to that in library path. delphi then cant find bpl and keeps coming b up with more errors.

    opened by davetrafford 14
  • Unable to install package (p4dlaz.lpk) with Lazarus

    Unable to install package (p4dlaz.lpk) with Lazarus

    Using Lazarus Trunk and FPC 3.2 on Intel MacOS, I am unable to install p4dlaz.lpk.

    1. Package fails to compile:
    PythonEngine.pas(2861,16) Error: Incompatible types: got "TThreadID" expected "NativeInt"
    
    1. lpk refers to a file that does not exist: lpk
    opened by neurolabusc 13
  • Potential AV on TPythonEngine.DoOpenDll (Linux)

    Potential AV on TPythonEngine.DoOpenDll (Linux)

    DoOpenDl loop for all PYTHON_KNOWN_VERSIONS defined versions. But if the version is not found then inherited is called with an empty name which causes AV. Inherited should be called only if UseLastKnownVersion is false.

    `procedure TPythonEngine.DoOpenDll(const aDllName : string); var i : Integer; begin if UseLastKnownVersion then for i:= Integer(COMPILED_FOR_PYTHON_VERSION_INDEX) downto 1 do begin RegVersion := PYTHON_KNOWN_VERSIONS[i].RegVersion; inherited DoOpenDll(PYTHON_KNOWN_VERSIONS[i].DllName); if IsHandleValid then begin DllName := PYTHON_KNOWN_VERSIONS[i].DllName; APIVersion := PYTHON_KNOWN_VERSIONS[i].APIVersion; Exit; end; end else begin RegVersion := SysVersionFromDLLName(aDllName); inherited; <--- HERE end; end;'

    Fixed 
    opened by cosina 12
  • Installation problem

    Installation problem

    Installation failure - "Can't load package Python_D$(Auto).bpl The system cannot find the file specified" - - Python_D.dprog loaded in Delphi 10.4. Installation documentation too vague to check that I have the correct setup. Using Anaconda3 installation.

    opened by drbond 12
  • Named parameters in VarPyth not cleared between function calls

    Named parameters in VarPyth not cleared between function calls

    Under some circumstances (sorry, I don't have minimal code to reproduce the error) named parameters in VarPyth not cleared between function calls, and function called without named parameters may recieve parameters from previous call with named parameters. Condition check in line 1091 of VarPyth.pas seems to be excessive; in my case commenting it out solved the problem: {if CallDesc^.NamedArgCount > 0 then }GetNamedParams;

    opened by mce2 8
Releases(with_delphi_2010_XE_support)
  • with_delphi_2010_XE_support(Jun 28, 2022)

  • python2(Oct 20, 2020)

    This is the last release with support for python 2.
    Python 2 is deprecated and no longer supported. If you do want to use python 2 with P4D please use this release.

    Source code(tar.gz)
    Source code(zip)
  • with_PythonAtom(Feb 17, 2020)

  • with_2.4-3.0-3.1_support(Jul 20, 2019)

    Python 2.4 is way too old and 3.0, 3.1 were hardly ever used and soon replaced by 3.2 and later. Support for these versions is being dropped. Thiis the last release before dropping such support, in case anyone wants compatibility with these versions.

    Source code(tar.gz)
    Source code(zip)
  • pre_unicode_support(Apr 24, 2018)

Aggressor script that gets the latest commands from CobaltStrikes web site and creates an aggressor script based on tool options.

opsec-aggressor Aggressor script that gets the latest commands from CobaltStrikes opsec page and creates an aggressor script based on tool options. Gr

JP 10 Nov 26, 2022
A program that lets you use your tablet's tilting to emulate an actual joystick on a Linux computer.

Tablet Tilt Joystick A program that lets you use your tablet's tilting to emulate an actual joystick on a Linux computer. It's called tablet tilt joys

1 Feb 07, 2022
A Bot that adds YouTube views to your video of choice

YoutubeViews Free Youtube viewer bot A Bot that adds YouTube views to your video of choice Installation git clone https://github.com/davdtheemonk/Yout

ProbablyX 5 Dec 06, 2022
Convert-Decimal-to-Binary-Octal-and-Hexadecimal

Convert-Decimal-to-Binary-Octal-and-Hexadecimal We have a number in a decimal number, and we have to convert it into a binary, octal, and hexadecimal

Maanyu M 2 Oct 08, 2021
ARA Records Ansible and makes it easier to understand and troubleshoot.

ARA Records Ansible ARA Records Ansible and makes it easier to understand and troubleshoot. It's another recursive acronym. What it does Simple to ins

Community managed Ansible repositories 1.6k Dec 25, 2022
Small projects for python beginners.

Python Mini Projects For Beginners I recently started doing the #100DaysOfCode Challenge in Python. I've used Python before, but I had switched to JS

Sreekesh Iyer 10 Dec 12, 2022
Animations made using manim-ce

ManimCE Animations Animations made using manim-ce The code turned out to be a bit complicated than expected.. It can be greatly simplified, will work

sparshg 17 Jan 06, 2023
Utils to quickly evaluate many 🤗 models on the GLUE tasks

Utils to quickly evaluate many 🤗 models on the GLUE tasks

Przemyslaw K. Joniak 1 Dec 22, 2021
Given tool find related trending keywords of input keyword

blog_generator Given tool find related trending keywords of input keyword (blog_related_to_keyword). Then cretes a mini blog. Currently its customised

Shivanshu Srivastava 2 Nov 30, 2021
firefox session recovery

firefox session recovery

Ahmad Sadraei 5 Nov 29, 2022
Custom Weapons 3 attribute support for Custom Weapons X

CW3toX Allows use of Custom Weapons 3 attributes in Custom Weapons X. Requiremen

2 Mar 01, 2022
Code needed for hybrid land cover change analysis for NASA IDS project

Documentation for the NASA IDS change analysis Poley 10/21/2021 Required python packages: whitebox numpy rasterio rasterio.mask os glob math itertools

Andrew Poley 2 Nov 12, 2021
CBO uses its Capital Tax model (CBO-CapTax) to estimate the effects of federal taxes on capital income from new investment

CBO’s CapTax Model CBO uses its Capital Tax model (CBO-CapTax) to estimate the effects of federal taxes on capital income from new investment. Specifi

Congressional Budget Office 7 Dec 16, 2022
Kivy program for identification & rotation sensing of objects on multi-touch tables.

ObjectViz ObjectViz is a multitouch object detection solution, enabling you to create physical markers out of any reliable multitouch solution. It's e

TangibleDisplay 8 Apr 04, 2022
Earth centric orbit propagation tool. Built from scratch in python.

Orbit-Propogator Earth centric orbit propagation tool. Built from scratch in python. Functionality includes: tracking sattelite location over time plo

Adam Klein 1 Mar 13, 2022
Type Persian without confusing words for yourself and others, in Adobe Connect

About In the Adobe Connect chat section, to type in Persian or Arabic, the written words will be confused and will be written and sent illegibly (This

Matin Najafi 23 Nov 26, 2021
A(Sync) Interface for internal Audible API written in pure Python.

Audible Audible is a Python low-level interface to communicate with the non-publicly Audible API. It enables Python developers to create there own Aud

mkb79 192 Jan 03, 2023
Flask html response minifier

Flask-HTMLmin Minify flask text/html mime type responses. Just add MINIFY_HTML = True to your deployment config to minify HTML and text responses of y

Hamid Feizabadi 85 Dec 07, 2022
A python package that computes an optimal motion plan for approaching a red light

redlight_approach redlight_approach is a Python package that computes an optimal motion plan during traffic light approach. RLA_demo.mov Given the par

Jonathan Roy 4 Oct 27, 2022
Team collaborative evaluation tracker.

Team collaborative evaluation tracker.

2 Dec 19, 2021