You are on page 1of 17
‘gitt22, 2207 Mixing Python and Delph Made Easy - Peardox Mixing Python and Delphi Made Easy Detailed P4D — Data Sciences Installation Instructions IMPORTANT MESSAGE FOR 10.4 Users The P4D Suite will currently NOT compile under 10.4 (or less) as PythonEnvironments has three lines of code that are Delphi 11 specific. This situation will be resolved soon... A Marriage of Convenience The recent release of a suite of Delphi components allows you to Embed a full Python Environment in a Delohi Avolication. It mav not be obvious whv vou'd want to do this in jebsite. If you continue to use this site we will We use cookies to ensure that we give you the be: hitpstipeardox.com/mixing-python-ané-delph+made-easy/ 17 anw22, 2207 Nocng Pon and Delphi Mage Easy Peardox For Delphi developers, the ability to add Al facilities to their projects is the most obvious benefit. As most Machine Learning libraries are written in C/C++ and then exposed for use via Python wrappers the ability to ‘talk Python’ from Delphi instantly opens up a huge range of highly advanced libraries to which you have zero native access. While the Python layer is involved its perceived lack of speed is irrelevant as Python is merely allowing access to a fast C/C++ library so the overhead is minimal. For Python developers, the main interface to your code is usually command-line in nature unless you use Tkinter, PyQT, or some other GUI library. However you decide to control your Python application if you plan on distributing your project for the use of others then the end user will, by necessity, need to install Python and a load of PIP/Conda packages just to get it working (there are exe compilers of course). With Delphi and the P4D components, you can add a pretty interface (it can even just issue command lines to your Python if you want) that is provided as one file. An embedded Python system is then built and populated with any packages you need the first time the application runs. Getting in Bed with Python The ability to at least control Python from Delphi has existed for many years via the Python4Delphi (P4D) project. P4D is, however, rather cumbersome to use and dependent on the user having a pre-installed Python Environment which somewhat detracts from the desire to use Python from Delphi. The introduction of the PythonEnvironments package and its sibling projects, however, remove many of the perceived shortcomings of Python4Delphi by allowing the deployment of a fully-fledged Embedded Python Environment along with PIP and Conda plus a growing selection of pre-packaged components via the Lightweight Python Wrappers package. The entire system can be installed and/or started on Application startup. While the We use cookies to ensure that we give you the be: jebsite. If you continue to use this site we will hitpstipeardox.com/mixing-python-ané-delph+made-easy/ air ava, 2207 Moc Pyton and Delph Mae Easy -Poardox executable increasing its size by about 40MB but requiring no external files so is extremely simple to ship as the Python part of things happens invisibly to the user. Component Suite https://github.com/Embarcadero/python4delphi https://github.com/Embarcadero/PythonEnviroments https://github.com/Embarcadero/Lightweight-Python-Wrappers https://github.com/Embarcadero/P4D-Data-Sciences https://github.com/Embarcadero/PythonPackages4Delphi Current Limitations Only Delphi versions 10.4.1 or greater are currently supported for PythonEnvironments and it's decendants The PAD suite of projects above supports Windows, Linux, MacOS (not iOS), and Android. Windows and Linux are both currently fully functional while Mac (currently) needs an external Python and Android only supports basic Python. Lucas, who writes most of the above apart from Python4Delphii, is currently looking at improving Mac support to allow Embedded Python to work as well as improving Android (proper PIP/Conda support is problematic ATM) The free Community Edition of Delphi supports Windows, Mac x64 (note NOT M1, ete) and Android, The full ‘Professional’ version of Delphi adds support for the Mac Arm64 (M1, M2, etc) system and the ‘Enterprise/Architect’ versions add Linux x64 support (even Steam Deck native Linux is possible) The Trial version of Delphi also supports everything but only for a month and a very small modification of the source is required if you want Linux x64 to run. iOS is not supported owing to Apple disapproval of code that runs other code — We use cookies to ensure that we give you the be: jebsite. If you continue to use this site we will hitpstipeardox.com/mixing-python-ané-delph+made-easy/ ane ania, 2207 Mang Python and Delphi Mace Easy - Peardox Arm64 Linux may be possible but an Arm64 version of PAServer would be required as would an Armé64 Linux compiler (that’s up to Embarcadero). The end results of mixing Delphi with Python are extremely rewarding like this project which is basically Python Command line with a pretty front end Getting Started As you may be of the Python or Pascal persuasion and possibly unfamiliar with the Delphi User Interface (if you're familiar with Lazarus this includes you) very little will be assumed ‘other than the fact that you're comfortable with using the command line once in a while and have some familiarity with general programming concepts — if you're not then go read some of the basics and come back later. Ifyou haven't already got them then you need to install a Git Client and a version of Delphi (Community Edition is fine), install them then come back here to continue. Beginning Installation hitpsspeardox.comfmixing-pythor-ané-delphtmade-easy! ant ertv22, 2207 oxng Python and Delphi Made Easy -Peardox more frustration and annoyance). That's why this Tutorial is here ~ to show you the correct way to install everything (even experts will get some of this wrong) First off you need to download the Component Suite. This is best performed by creating a new directory specifically for the P4D packages. It is suggested that you create a C:\Delphi directory then within that one create another called P4DSuite ending up with a directory C\Delphi\P4DSuite. With that directory selected in Windows Explorer hold down the Shift key and Right Click on the P4DSuite directory then click on the Open PowerShell Window Here option from the pop-up menu that just opened Now you have a command prompt open in C:\Delphi\P4DSuite (or whatever you chose***) you can download the five packages that comprise the suite. Start off by typing (or cut & acta if hitpsspeardox.con/mixing-pythor-and-dolphtmade-sasy! sir ava, 2207 Moc Pyton and Delph Mae Easy -Poardox Press Enter and the very latest version of python4delphi will be downloaded from its GitHub repository into a subdirectory called python4delphi Once that one’s done repeat the process using the following four commands (the PythonEnvironment one is the biggest) git clone https://github.com/Embarcadero/PythonEnviroments git clone https://github.com/Embarcadero/Lightweight-Python-Wrappers git clone https://github.com/Embarcadero/P4D-Data-Sciences git clone https://github.com/Embarcadero/PythonPackages4Delphi OK, with all five repositories installed close the command-line window, you won't need it anymore for this procedure. *** Note that C:\Delphi\P4DSuite should be replaced with your own directory wherever you see it from now on Installalling the Python4Delphi Suite The following steps must be completed in the given order. Each package you are about to install after the first depends on the ones before it so the order of installation is vital and the most likely cause of installation errors. Additionally, as you install each package, Delphi needs to be told where to find the files you just built so that the packages you install after the current one know where to look for the files they in turn require. Python4Delphi Let's start with python4delphi. Without Delphi, open use Windows Explorer to navigate to C.\Delphi\P4DSuite\python4delphi\Packages and you will see a screen similar to this. We use cookies to ensure that we give you the be: 1 continue to use this site we will hitpstipeardox.com/mixing-python-ané-delph+made-easy/ eur ari22, 2207 Moxing Python and Delphi Made Easy - Peardox Here you will see a file named P4DComponentSuite.groupproj - this is the one you want so double click on it and Delphi will open (there is another groupproj file in this directory — its contents are a subset of the one you're opening that skip the Windows stuff - you can safely ignore it) On the Righthand side of the Delphi window that just opened you'll see an ‘explorer-like’ treeview display of the files in this project group. hitpsspeardox.conmixing-pythor-and-dolph+made-sasy! mt ‘git122, 2207 Moxing Python and Delphi Made Easy - Peardox Eon altel) Xan Cee sel) — The drop-down icons in the first image allow you to select the Platform (Windows etc) and Build Configuration (Debug/Release). The build mode is currently set to Windows 32-bit Release. Even if you never intend to write or release anything for Windows 32 bit you need this version of the components as Delphi uses them extensively when building forms visually etc. The parts of the project tree on the left-hand side starting with the letters ‘DCL’ are the actual visual components you'll drag and drop onto your form later. As shown in the middle image above Right Click on the very top item in the list and the drop-down menu shown will pop up. Click on Build All and a window will open in the center of Delphi showing it's progress as it builds everything. When it's finished you can close that window by clicking the OK button (you can also check the box marked “Automatically close on successful compile” and it'll close itself so you don’t have to) Now click on each of the ‘dcl’... folders while holding down the Ctrl key and all of them will become selected, Right Click and the drop-down shown in the right image will appear. Click on Install and the components in this package will be installed making them available for use later in Delphi's Visual Editor. The installation of components should usually only be done when the project is in Windows 32-bit Release (you can install as debug but this is normally only used when writing components in the first place) Now you have to do all that again apart from the Install part for the Debug versions of the hitpsspeardox.comfmixing-pythor-ané-delphtmade-easy! ane nize, 2207 Mixing Pyhon and Delph Made Easy -Peardox Congratulations, you've just installed the pythonddelphi package. Now you need to tell Delphi where it can find the files you just created (you created a load of files when you did the Build All and Install stuff). If you switch back to Windows Explorer you will find a new directory has been created (C:\Delphi\P4DSuite\python4delphi\lib), Click on that directory and copy its location to the clipboard (Ctrl+C) from the Windows Explorer Address Bar (this will make things a lot easier for you in a second) From the main Delphi menu select Tools -> Option: that window click on Language -> Delphi -> Library pee cry ‘Component Tootbar as ae ECE eer Se pities ere ae Maneger erred Der ees a a 5 Sree EREe fom ee hitpsspeardox.comfmixing-pythor-ané-delphtmade-easy! enr nize, 2207 oxng Python and Delphi Made Easy -Peardox Make sure that the Selected Library (1) is the same as you just built. This should be automatic but it can get confused once in a while. Click on the button [...] at the end of Library Path (2) a dialog window will open. [© directories x ce Click on the Folder icon near the bottom and a Directory Selection dialog will open. As you've got “C:\Delphi\P4DSuite\pythonddelphi\lib” in your clipboard from earlier you can save a lot of messing around by simply pasting the location into the box by pressing Ctrl+V and pressing Enter. One way or another you're now looking at the right part of your drive. There's a folder called Win32 here, select that then select Release (you'll do Debug in a moment). Finally, close the dialog box by clicking the Select Folder button and your dialog box should look similar to the image above and the Add button should be clickable —so Click it to add the Release Folder to this list of directories (make sure it's added - you should see it near the bottom of the scrollable list). Once you're happy press the OK button and this dialog will close. Now click the button [...] at the end Debug DCU Path (3) a dialog window will open. The process here is almost identical to the one you just did ~ you want to add the Debug folder so click the Folder icon in this dialog and paste the path you've got in your hitpsspeardox.comfmixing-pythor-ané-delphtmade-easy! son7 ‘gitt22, 2207 Mocng Python and Delph Made Easy - Peardox Time to do Windows 64 bit. *** Important note for Delphi Alexandria 11.2 Users Only *** Before trying Win64 check your Library Paths for Windows 64 Release points at $(BDSCOMMONDIR)\Dcp\$ (Platform) as we have noticed that the \($Platform) part may erroneously be omitted. If you have $(BDSCOMMONDIR)\Dcp set for Win64 it needs changing or the linker will try using the 32-bit library. *** Fixed in RAD Studio 11.2 Patch #1 *** This is basically a repeat of everything you did for Windows 32 apart from the fact that you DONT install the components this time and when you set the Library and Debug DCU paths you'll use the Win64 Folders rather than the Win32 ones. Switch the Active Platform to Windows 64 (the clearly marked icon fourth image above) and go through the same steps apart from the Install one and selecting the Win64 Directories when setting up paths rather than the Win32 ones. Once you've completed that task you've completed the installation of all versions of Windows available. The observant among you will notice that there are more platforms available than just Windows and may be tempted to give it a go. Feel free to play around but note that the Install step is ONLY required for Windows 32-bit Release. It should also be noted that you may have issues with Build All, this can be avoided by only selecting the targets ending in .so or .dylib for the non-Windows platforms. Please exit Delphi and say you don’t want to save any changes - this is useful if you ever need to install things again as everything will be the same as the instructions above say. One down, four to go From here on in installing the rest is basically repetition of the above with some small We use cookies to ensure that we give you the be: jebsite. If you continue to use this site we will ok hitpstipeardox.com/mixing-python-ané-delph+made-easy/ nar ava, 2207 Nocng Pon and Delphi Mage Easy Peardox components that use the packages you've already installed and are not dependent on each other. PythonEnvironments Switch to C:\Delphi\P4DSuite\PythonEnviroments\packages and double click on P4DPythonEnvironmentsComponentSuite.groupproj (these are easy to spot, they're the only ones marked with type being "Embarcadero RAD Studio Project Group” For the Library setup Cut+Paste use C:\Delphi\P4DSuite\PythonEnviroments\lib as your starting point PythonEnvironments additionally needs C.\Delphi\P4DSuite\PythonEnviroments\src\AddOn adding to the Library Path (2) and the Debug DCU Path (3) when you get to it as a few components need that path in order to. find some files they need Lightweight-Python-Wrappers Switch to C:\Delphi\P4DSuite\Lightweight-Python-Wrappers\packages and double click on P4DLightweightWrappersComponentSuite.groupproj For the Library setup Cut+Paste use C:\Delphi\P4DSuite\Lightweight-Python-Wrappers\lib as your starting point P4D-Data-Sciences Switch to C:\Delphi\P4DSuite\P4D-Data-Sciences (note this time it's not in packages) and double click on P4DDataSciencesComponentSuite.groupproj For the Library setup, Cut+Paste use C:\Delphi\P4DSuite\P4D-Data-Sciences\sre\lib as your starting point (yes, this one is different as well) This one has a lot of components PythonPackages4Delphi Switch to C:\Delphi\P4DSuite\PythonPackages4Delphi (again not in packages) and double flick An DuthanDaclanacsNalnhi arniunnesi We use cookies to ensure that we give you the be: jebsite. If you continue to use this site we will hitpstipeardox.com/mixing-python-ané-delph+made-easy/ sar ‘gitt22, 2207 Moxing Python and Delphi Made Easy - Peardox Final Sanity Check Ifyou did everything correctly your library dialogs should each have six entries for C\Delphi\P4DSuite in the four Library dialog boxes like this ‘winaa Release Wins? Debug If you inspect each dialog box you will notice that, with the exception of src\AddOn, the end of the path in each case matches the Platform\Release of the dialog box you chose to open. It is highly recommended that you make sure everything looks right (i.e. as pictured above) and that you don't have, for example, a Win32 directory in a Win64 dialog. This is very easy to do, especially if you aren't methodical and, for example, do all the dialog boxes at once ~ it's very tempting to do that, especially near the end of the installation when you're familiar with the correct way of installing the components. Next Steps hitpsspeardox.com/mixing-pythor-ané-delphtmade-easy! san7 ava, 2207 Moc Pyton and Delph Mae Easy -Poardox We have a Discord, especially for Python4Delphi where you can come and ask Myself, @Imbelo (he writes all this), and @priyatham10 (he does a load of Python stuff for us) all about the P4D Suite @ pviscora Click the Discord image above to come and chat about the P4D Suite The End (for Now) We use cookies to ensure that we give you the best our website. If you continue to use this hitpstipeardox.com/mixing-python-ané-delph+made-easy/ sar Moxing Python and Delphi Made Easy - Peardox Pyton 5 peace res ‘gitt22, 2207 Dens CSc eae i eee eet es ce) Seer DEE e et) 7 Python = Date Sdence Ecosystem Dry oa Creer) Ee tae Oud Sears See aoe ae ti pence feet eae re Paso hitpsspeardox.comfmixing-pythor-ané-delphtmade-easy! sor ‘gitt22, 2207 Mixing Python and Delph Made Easy - Peardox The Tip Jar Support my many projects with a donation of any size Donate 3D Models SHOP THOUSANDS OF PROFESSIONAL EPEC yas Witt SKETCHFAB.COM/STORE hitpstipeardox.com/mixing-python-ané-delph+made-easy/ sen7 ‘gitt22, 2207 Mixing Python and Delph Made Easy - Peardox Recent Posts How to Install Python Support in Delphi Bulk Background Removal ‘Automating Al Art Creation Merging Mixamo models using Godot Game Tools More Linux Installation Instructions Recent Comments Admin on Linux rkimber on Linux rkimber on Linux Admin on CUDA 9.0 + cuDNN - Win10 joelnisson on CUDA 9.0 + cuDNN — Win10 Pearde We use cookies to ensure that we give you the best our website. If you continue to use this assume happ hitpstipeardox.com/mixing-python-ané-delph+made-easy/ amir

You might also like