在Python 2.6, 3.0下使用P4D

Using P4D with Python 2.6, 3.0
2011-03-17 17:09

Using P4D with Python 2.6, 3.0

Python 2.6 and Python 3.0 rely on Microsoft C++ dynamic link libraries which are installed using Side by Side installation and are no longer placed in the Windows System32 directory.

This affects Delphi programs using P4D. The problem that will occur is that you will not be able to load c-extensions such as socket.pyd, ctypes.pyd and the importing of modules such socket and ctypes will fail.

To resolve this you need to add a manifest to your Delphi application. Here is an example of the manifest file that PyScripter uses.

File XP_UAC.manifest

<?xml version="1.0"encoding="UTF-8"standalone="yes"?> 

<assemblyxmlns="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>  

 <trustInfoxmlns="urn:schemas-microsoft-com:asm.v3"> 

   <security> 

     <requestedPrivileges> 

       <requestedExecutionLevellevel="asInvoker"/> 

     </requestedPrivileges> 

   </security> 

 </trustInfo> 

 <asmv3:application> 

   <asmv3:windowsSettingsxmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> 

     <dpiAware>true</dpiAware> 

   </asmv3:windowsSettings> 

 </asmv3:application> 

</assembly> 

The key here is the dependency on Microsoft.VC90.CRT.

To use this manifest in Delphi you need to create a file say

File XP_UAC.rc

 

       
         
1 24 ".\XP_UAC.manifest"

 

then compile the file ito XP_UAC.res using brcc32.exe and link the resulting file into your application.

the way is adding {$R XP_UAC.res} to the project file,under the {$R *.res} )

这是pyscripter网上看到的一个issue,我按照以上方法测试,还需要如下设定才能正常工作:

in pythonengine property tab

‍keep set  “UseLastKnownVersion” to True

‍keep ‍set   "DLLName"  to  python26

on your PythonEngine component and adjust your define:

{$DEFINE PYTHON26}

which you can do in the project options of Delphi 7.  
Just add PYTHON26 to the "conditional defines" dialog box 

and then modify the PythonEngine.pas code as below,that is to add the python26.dll version.

1 PYTHON_KNOWN_VERSIONS: array[1..10] of TPythonVersionProp =
2 ( (DllName: 'python14.dll'; RegVersion: '1.4'; APIVersion: 1006; CanUseLatest: False),
3 (DllName: 'python15.dll'; RegVersion: '1.5'; APIVersion: 1007; CanUseLatest: False),
4 (DllName: 'python16.dll'; RegVersion: '1.6'; APIVersion: 1008; CanUseLatest: False),
5 (DllName: 'python20.dll'; RegVersion: '2.0'; APIVersion: 1009; CanUseLatest: True),
6 (DllName: 'python21.dll'; RegVersion: '2.1'; APIVersion: 1010; CanUseLatest: True),
7 (DllName: 'python22.dll'; RegVersion: '2.2'; APIVersion: 1011; CanUseLatest: True),
8 (DllName: 'python23.dll'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True),
9 (DllName: 'python24.dll'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True),
10 (DllName: 'python25.dll'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True),
11 (DllName: 'python26.dll'; RegVersion: '2.6'; APIVersion: 1013; CanUseLatest: True) );


 

 按照如上设置后就可以在python26下正常工作了

 

你可能感兴趣的:(python)