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)

Python’s bokeh, holoviews, matplotlib, plotly, seaborn package-based visualizations about COVID statistics eventually hosted as a web app on Heroku

COVID-Watch-NYC-Python-Visualization-App Python’s bokeh, holoviews, matplotlib, plotly, seaborn package-based visualizations about COVID statistics ev

Aarif Munwar Jahan 1 Jan 04, 2022
The update manager for the ERA App (era.sh)

ERA Update Manager This is the official update manager used in the ERA app (see era.sh) How it works Once a new version of ERA is available, the app l

Kian Shahriyari 1 Dec 29, 2021
Un script en python qui permet d'automatique bumpée (disboard.org) tout les 2h

auto-bumper Un script en python qui permet d'automatique bumpée (disboard.org) tout les 2h Pour la première utilisation, 1.Lancer Install.bat 2.(faire

!! 1 Jan 09, 2022
A general illumination correction method for optical microscopy.

CIDRE About CIDRE is a retrospective illumination correction method for optical microscopy. It is designed to correct collections of images by buildin

Kevin Smith 31 Sep 07, 2022
LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visualization exercises.

libreMind Meditation exercises What is it? LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visua

1 May 24, 2022
Submission from Team OMR for the TRI-NIT Hackathon

Submission from Team OMR for the TRI-NIT Hackathon

0 Feb 01, 2022
A modern Python build backend

trampolim A modern Python build backend. Features Task system, allowing to run arbitrary Python code during the build process (Planned) Easy to use CL

Filipe Laíns 39 Nov 08, 2022
Small tool to use hero .json files created with Optolith for The Dark Eye/ Das Schwarze Auge 5 to perform talent probes.

DSA5-ProbeMaker A little tool for The Dark Eye 5th Edition (Das Schwarze Auge 5) to load .json from Optolith character generation and easily perform t

2 Jan 06, 2022
Заглушки .NET библиотек для IronPython

Код репозитория основан на ironpython-stubs. Выражаю gtalarico бесконечную благодарность за вклад в развитие сообщества разработчиков скриптов и плаги

12 Nov 23, 2022
A module comment generator for python

Module Comment Generator The comment style is as a tribute to the comment from the RA . The comment generator can parse the ast tree from the python s

飘尘 1 Oct 21, 2021
Bots in moderation and a game (for now)

Tutorial: come far funzionare il bot e durarlo per 24/7 (o quasi...) Ci sono 17 passi per seguire: Andare sul sito Replit https://replit.com/ Vedrete

ZacyKing 1 Dec 27, 2021
Shows a pixel art of any Pokémon in your terminal!

pokemon-icat This script is inspired by this project, but since the output heavily depends on the font of your terminal, i decided to make a script th

ph04 52 Dec 22, 2022
With the initiation of the COVID vaccination drive across India for all individuals above the age of 18, I wrote a python script which alerts the user regarding open slots in the vicinity!

cowin_notifier With the initiation of the COVID vaccination drive across India for all individuals above the age of 18, I wrote a python script which

13 Aug 01, 2021
Block the annoying Token Grabbers on your discord

General We have seen that in the last time many discord servers are infected by fake discord nitro links we want to put an end to this and have develo

BadTiger Network 2 Jul 16, 2022
Grail(TM) is a web browser written in Python

Grail is distributed in source form. It requires that you have a Python interpreter and a Tcl/Tk installation, with the Python interpreter configured for Tcl/Tk support.

22 Oct 18, 2022
Providing a working, flexible, easier and faster installer than the one officially provided by Arch Linux

Purpose The purpose is to bring more people to Arch Linux by providing a working, flexible, easier and faster installer than the one officially provid

André Luís 0 Nov 09, 2022
A random cat fact python module

A random cat fact python module

Fayas Noushad 4 Nov 28, 2021
My HA controller for veg and flower rooms

HAGrowRoom My HA controller for veg and flower rooms I will do my best to keep this updated as I change, add and improve. System heavily uses custom t

4 May 25, 2022
This Open-Source project is great for sensor capture and storage solutions.

Phase 1 This project helps developers in the creation of extended realities that communicate with Arduino and require the security of blockchain stora

Wolfberry, LLC 10 Dec 28, 2022
frida-based ceserver. iOS analysis is possible with Cheat Engine.

frida-ceserver frida-based ceserver. iOS analysis is possible with Cheat Engine. Original by Dark Byte. Usage Install frida on iOS. python main.py Cyd

KenjiroIchise 89 Jan 08, 2023