Install python4delphi and python4delphi

Source: Internet
Author: User

Install python4delphi and python4delphi
Environment setup:

Currently, p4d supports XE7. Unfortunately, the googlecode is about to be closed. I wonder if the author will continue to update it on github.

Because this open-source project has a long history, you may need to manually modify the relevant file reference after obtaining the source code. After all, you need to take into account the earlier versions of delphi.

Step1. install python4delphi

1. First, install the component and open the corresponding version of Python _??. Dpk: Compile and modify references. After XE, many units have prefixed with VCL and FMX and need to be specified manually,

After compilation is successful, select release mode to install

2. Add the search path: xxxxx \ python4delphi \ Components \ Sources \ Core to our project.

3. In system32 or sysWOW64 of the system disk, locate python27.dll and put it in the program output directory.

Step2. Add the definition file P4D to project. dpr.
----------------------------
Add {$ I Definition. Inc} to Delphi project. dpr before uses}
----------------------------
Step3. use pythonengince and other components
----------------------------
Set attributes of the pythonengince component.
UseLastKnownVersion = False
DLLName = 'python27'
DllPath = 'C: \ WINDOWS \ system32'
----------------------------
Step 4. Solve the run as administrator problem before publishing the application,
----------------------------
(A) Microsoft. VC90.CRT and Microsoft. Windows. Common-Controls are required as resources to be added to the delphi project. Otherwise, an error is returned when the c-extensions Module of python is loaded.
(B) Create the XP_UAC.manifest file. For details, see the following section.
(C) Create the XP_UAC.rc file. content:
1 24 XP_UAC.manifest
Where: 1 indicates the resource number, 24-the resource type is RTMAINIFEST, and UAC. manifest indicates the name of the manifest file.
(D) Use brcc32 of delphi to compile XP_UAC.rc into XP_UAC.res
Command: brcc32 XP_UAC.rc
(E) source code in Delphi project. dpr
(1) After {$ R *. res}, add {$ R XP_UAC.res}
======================================
Deploy python4delphi applications
======================================
Method 1. As with development, install python and python 3rd packages honestly, and then your delphi program should be ready for use.
Method 2. Like dreampie, package the python environment and release it together with the exe. There are dedicated py2exe, cx_freeze, and other production tools.
======================================
Content of XP_UAC.manifest
======================================
C: \ WINDOWS \ WinSxS directory for Windows. common-Controls and Microsoft. VC90.CRT. if the version can be found and consistent, you only need to modify the name of the PyScripter. if the two files are not found, you need to download Microsoft Visual C ++ 2008 Redistributable Package from the Microsoft official website, and compare the version number with publicKeyToken.
<? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<Assembly xmlns = "urn: schemas-microsoft-com: asm. v1" manifestVersion = "1.0">
<AssemblyIdentity
Version = "1.0.0.0"
ProcessorArchitecture = "*"
Name = "PyScripter"
Type = "win32"/>
<Dependency>
<DependentAssembly>
<AssemblyIdentity
Type = "win32"
Name = "Microsoft. Windows. Common-Controls"
Version = "6.0.0.0"
ProcessorArchitecture = "*"
PublicKeyToken = "6595b64144ccf1df"
Language = "*"/>
</DependentAssembly>
</Dependency>
<Dependency>
<DependentAssembly>
<AssemblyIdentity
Type = "win32"
Name = "Microsoft. VC90.CRT"
Version = "9.0.21022.8"
ProcessorArchitecture = "x86"
PublicKeyToken = "1fc8b3b9a1e18e3b"
Language = "*"/>
</DependentAssembly>
</Dependency>
<TrustInfo xmlns = "urn: schemas-microsoft-com: asm. v3">
<Security>
<RequestedPrivileges>
<RequestedExecutionLevel level = "asInvoker"/>
</RequestedPrivileges>
</Security>
</TrustInfo>
<Asmv3: application>
<Asmv3: windowsSettings xmlns = "http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<DpiAware> true </dpiAware>
</Asmv3: windowsSettings>
</Asmv3: application>
</Assembly>
======================================
PYTHONPATH settings
======================================
You can add our own path to the pythonpath in the TPythonEngine. OnSysPathInit event.
If the code is not added, we need to modify the registry at HKEY_LOCAL_MACHINE \ SOFTWARE \ Python \ PythonCore \ 2.7 \ PythonPath and add our path.
Note: The TPythonEngine. OnPathInitialization event is useful only when no PythonPath is defined in the registry. Therefore, it is not recommended.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.