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)

Owner
null
UdemyPy is a bot that hourly looks for Udemy free courses and post them in my Telegram Channel: Free Courses.

UdemyPy UdemyPy is a bot that hourly looks for Udemy free courses and post them in my Telegram Channel: Free Courses. How does it work? For publishing

null 88 Dec 25, 2022
A collection of UIKit components that can be used as a Wagtail StreamField block.

Wagtail UIKit Blocks A collection of UIKit components that can be used as a Wagtail StreamField block. Available UIKit components Container Grid Headi

Krishna Prasad K 13 Dec 15, 2022
Gba-free-fonts - Free font resources for GBA game development

gba-free-fonts Free font resources for GBA game development This repo contains m

null 28 Dec 30, 2022
Table (Finnish Taulukko) glued together to transform into hands-free living.

taulukko Table (Finnish Taulukko) glued together to transform into hands-free living. Installation Preferred way to install is as usual (for testing o

Stefan Hagen 2 Dec 14, 2022
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source.

Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source. Getting Started This is an example of ho

null 14 Apr 10, 2022
A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.

deep-translator Translation for humans A flexible FREE and UNLIMITED tool to translate between different languages in a simple way using multiple tran

Nidhal Baccouri 806 Jan 4, 2023
Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build prortfolios

Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build prortfolios

Salma Saidane 64 Sep 28, 2022
A free and open-source chess improvement app that combines the power of Lichess and Anki.

A free and open-source chess improvement app that combines the power of Lichess and Anki. Chessli Project Activity & Issue Tracking PyPI Build & Healt

null 93 Nov 23, 2022
A free and powerful system for awareness and research of the American judicial system.

CourtListener Started in 2009, CourtListener.com is the main initiative of Free Law Project. The goal of CourtListener.com is to provide high quality

Free Law Project 332 Dec 25, 2022
Fisherman is a free open source fishing bot written in python.

Fisherman is a free open source fishing bot written in python.

Pure | Cody 33 Jan 29, 2022
Free APN For Python

Free APN For Python

XENZI GANZZ 4 Apr 22, 2022
World's best free and open source ERP.

World's best free and open source ERP.

Frappe 12.5k Jan 7, 2023
Purge your likes and wall comments from VKontakte. Set yourself free from your digital footprint.

vk_liberator Regain liberty in the cruel social media world. This program assists you with purging your metadata from Russian social network VKontakte

null 20 Jun 11, 2021
A free website that keeps the people informed about housing and evictions.

Eviction Tracker Currently helping verify detainer warrant data for middle Tennessee - via Middle TN DSA - Red Door Collective Features Presents data

Red Door Collective 7 Dec 14, 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

null 1 May 24, 2022
Absolute solvation free energy calculations with OpenFF and OpenMM

ABsolute SOLVantion Free Energy Calculations The absolv framework aims to offer a simple API for computing the change in free energy when transferring

null 7 Dec 7, 2022
Your self-hosted bookmark archive. Free and open source.

Your self-hosted bookmark archive. Free and open source. Contents About LinkAce Support Setup Contribution About LinkAce LinkAce is a self-hosted arch

Kevin Woblick 1.7k Jan 3, 2023
An open letter in support of Richard Matthew Stallman being reinstated by the Free Software Foundation

An open letter in support of RMS. To sign, click here and name the file <username>.yaml (replace <username> with your name) with the following content

null 2.4k Jan 7, 2023
Free version of Okuru selfbot, okuru.xyz

Indigo Selfbot Free OpenSource selfbot, Premium version can be found at https://okuru.xyz (5$.) Usage python[3] main.py Installation To install you ca

Dimitri Demarkus 31 Aug 7, 2022