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)

Winxp_python3.6.15 - Python 3.6.15 For Windows XP SP3

This is Python version 3.6.15 Copyright (c) 2001-2021 Python Software Foundation. All rights reserved. See the end of this file for further copyright

Alex Free 13 Sep 11, 2022
Python interface to IEX and IEX cloud APIs

Python interface to IEX Cloud Referral Please subscribe to IEX Cloud using this referral code. Getting Started Install Install from pip pip install py

IEX Cloud 41 Dec 21, 2022
A python tool that creates issues in your repos based on TODO comments in your code

Krypto A neat little sidekick python script to create issues on your repo based on comments left in the code on your behalf Convert todo comments in y

Alex Antoniou 4 Oct 26, 2021
List of all D&D 5e monsters: WotC + popular third-party sourcebooks

Xio's Guide to Monsters If you're a DM like me, and you have multiple sources of D&D 5e monsters that include WotC as well as third-party suppliers, y

20 Jan 06, 2023
Machine Learning powered app to decide whether a photo is food or not.

Food Not Food dot app ( 🍔 🚫 🍔 ) Code for building a machine Learning powered app to decide whether a photo is of food or not. See it working live a

Daniel Bourke 48 Dec 28, 2022
Машинное обучение на ФКН ВШЭ

Курс "Машинное обучение" на ФКН ВШЭ Конспекты лекций, материалы семинаров и домашние задания (теоретические, практические, соревнования) по курсу "Маш

Evgeny Sokolov 2.2k Jan 04, 2023
Simple project to learn more about Bézier curves

Python Quadratic Bézier Simple project to learn more about Bézier curves. On this project i used some api's to graphics and gui pygame thorpy in theor

Kenned Ferreira 2 Mar 06, 2022
Add-In for Blender to automatically save files when rendering

Autosave - Render: Automatically save .blend, .png and readme.txt files when rendering with Blender Purpose This Blender Add-On provides an easy way t

Volker 9 Aug 10, 2022
A Snakemake workflow for standardised sc/snRNAseq analysis

single_snake_sequencing - sc/snRNAseq Snakemake Workflow A Snakemake workflow for standardised sc/snRNAseq analysis. Every single cell analysis is sli

IMS Bio2Core Facility 1 Nov 02, 2021
Small exercises to get you used to reading and writing Python code!

Pythonlings Welcome to Pythonlings, an automated Python tutorial program (inspired by Rustlings and Haskellings). WIP This program is still working in

鹤翔万里 5 Sep 23, 2022
HatAsm - a HatSploit native powerful assembler and disassembler that provides support for all common architectures

HatAsm - a HatSploit native powerful assembler and disassembler that provides support for all common architectures.

EntySec 8 Nov 09, 2022
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
Expression interpreter written in Python

Calc Interpreter An interpreter modeled after a calculator implemented in Python 3. The program currently only supports basic mathematical expressions

1 Oct 17, 2021
Cobalt Strike Sleep Python Bridge

This project is 'bridge' between the sleep and python language. It allows the control of a Cobalt Strike teamserver through python without the need for for the standard GUI client. NOTE: This project

Cobalt Strike 140 Jan 04, 2023
Delayed iteration for polling and retries.

Does Python need yet another retry / poll library? It needs at least one that isn't coupled to decorators and functions. Decorators prevent the caller

A. Coady 22 Dec 29, 2022
Template for pre-commit hooks

Pre-commit hook template This repo is a template for a pre-commit hook. Try it out by running: pre-commit try-repo https://github.com/stefsmeets/pre-c

Stef Smeets 1 Dec 09, 2021
A wide AOI generator tool.

Dark Generator A wide AOI generator tool. Information Installation To Install you have to have python 3.x and pip installed on your system. If you hav

Darkest Surface 12 Dec 26, 2022
Simple calculator with random number button and dark gray theme created with PyQt6

Calculator Application Simple calculator with random number button and dark gray theme created with : PyQt6 Python 3.9.7 you can download the dark gra

Flamingo 2 Mar 07, 2022
Apache Airflow - A platform to programmatically author, schedule, and monitor workflows

Apache Airflow Apache Airflow (or simply Airflow) is a platform to programmatically author, schedule, and monitor workflows. When workflows are define

The Apache Software Foundation 28.6k Dec 28, 2022
A sandpit for textual related things

A sandpit repo for testing textual related things.

Craig Gumbley 1 Nov 08, 2021