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)

Application launcher and environment management

Application launcher and environment management for 21st century games and digital post-production, built with bleeding-rez and Qt.py News Date Releas

10 Nov 03, 2022
Convert Beat Saber maps to Tesla light shows!

Tesla x Beat Saber - Light Show Converter Convert Beat Saber maps to Tesla light shows! This project requires FFMPEG and all packages from requirement

HLVM 20 Dec 21, 2022
My attempt at this years Advent of Code!

Advent-of-code-2021 My attempt at this years Advent of Code! day 1: ** day 2: ** day 3: ** day 4: ** day 5: ** day 6: ** day 7: ** day 8: * day 9: day

1 Jul 06, 2022
End-to-End text sumarization, QAs generation using flask.

Help-Me-Read A web application created with Flask + BootStrap + HuggingFace 🤗 to generate summary and question-answer from given input text. It uses

Ankush Kuwar 12 Nov 13, 2022
Tool for working with Direct System Calls in Cobalt Strike's Beacon Object Files (BOF) via Syswhispers2

Tool for working with Direct System Calls in Cobalt Strike's Beacon Object Files (BOF) via Syswhispers2

150 Dec 31, 2022
Custom component to calculate estimated power consumption of lights and other appliances

Custom component to calculate estimated power consumption of lights and other appliances. Provides easy configuration to get virtual power consumption sensors in Home Assistant for all your devices w

Bram Gerritsen 552 Dec 28, 2022
A common, beautiful interface to tabular data, no matter the format

rows No matter in which format your tabular data is: rows will import it, automatically detect types and give you high-level Python objects so you can

Álvaro Justen 834 Jan 03, 2023
A simple calculator made with tkinter.

Simple Calculator A simple calculator made with tkinter. Requirements None, only you need to have windows 😉 ...Enjoy! Installation Clone this reposit

Abhyush 2 Jan 11, 2022
This speeds up PyCharm's package index processes and avoids CPU & memory overloading

This speeds up PyCharm's package index processes and avoids CPU & memory overloading

1 Feb 09, 2022
Participants of Bertelsmann Technology Scholarship created an awesome list of resources and they want to share it with the world, if you find illegal resources please report to us and we will remove.

Participants of Bertelsmann Technology Scholarship created an awesome list of resources and they want to share it with the world, if you find illegal

Wissem Marzouki 29 Nov 28, 2022
Extend the maya channel box with searchability and colour

channel-box-plus will add search-ability over its attributes, and it will colour user defined attributes, making them easier to distinguish.

Robert Joosten 12 Jun 08, 2022
Fetch data from an excel file and create HTML file

excel-to-html Problem Statement! - Fetch data from excel file and create html file Excel.xlsx file contain the information.in multiple rows that is ne

Vivek Kashyap 1 Oct 25, 2021
A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

3 May 01, 2022
It's an .exe file that can notify your chia profit and warning message every time automatically.

chia-Notify-with-Line 警示程式 It's an .exe file that can notify your chia profit and warning message every time automatically. 這是我自行設計的小程式,有轉成.exe檔了,可以在沒

You,Yu 1 Oct 28, 2021
Pydesy package description (EN)

Pydesy package description (EN) Last version: 0.0.2 Geodetic library, which includes the following tasks: 1. Calculation of theodolite traverse (tachy

1 Feb 03, 2022
奇遇淘客服务器端

奇遇淘客 APP 服务器端 警告 正在使用 v0.2.0 版本的用户,请尽快升级到 v0.2.1。 v0.2.0 版本的 Docker 镜像中包含了有问题的 aiohttp。 奇遇淘客代码库 奇遇淘客 iOS APP 奇遇淘客 Android APP 奇遇淘客文档 服务器端文档 Docker 使用

奇遇科技 92 Nov 09, 2022
Expose multicam options in the Blender VSE headers.

Multicam Expose multicam options in the Blender VSE headers. Install Download space_sequencer.py and swap it with the one that comes with the Blender

4 Feb 27, 2022
rebalance is a simple Python 3.9+ library for rebalancing investment portfolios

rebalance rebalance is a simple Python 3.9+ library for rebalancing investment portfolios. It supports cash flow rebalancing with contributions and wi

Darik Harter 5 Feb 26, 2022
Python PID Controller and Process Simulator (FOPDT) with GUI.

PythonPID_Simulator Python PID Controller and Process Simulator (FOPDT) with GUI. Run the File. Then select Model Values and Tune PID.. Hit Refresh to

19 Oct 14, 2022
Python 101 Forever

🚀 Python 101 Forever 🚀 Official Python 101 Forever GitHub repository. START HERE - CHECK README SUBSCRIBE FOR UPDATES HERE Sponsors Contac

Hack Bulgaria 58 Nov 30, 2022