Python 开发桌面程序, 之前写过一个使用IronPython的博客. 下面这个方案使用 delphi 作为主开发语言,通过 python4delphi 控件包将 python 作为 script 嵌入其中, Delphi + Python, 偏上加偏, pyscripter IDE 算是这种方案唯一的成果.

=================================
Delphi + Python的特点
=================================
Delphi GUI方面还是很强, 但第3方类库太缺了.
Python正好相反, pypi的类库太丰富了. 两者结合在一起, 简直是取长补短的典范.

=================================
 使用 python4delphi 的开发设置
=================================
----------------------------
Step1. 安装 python2.7 和 python4delphi VCL.
----------------------------
安装python27:  下载并安装 python2.7 for windows版. python27 安装后, 在c:\WINDOWS\system32就有了 python27.dll.
安装python4delphi: svn下载最新版的 python4delphi, http://code.google.com/p/python4delphi, 该版本已经支持 python2.7 和python3.3了. 不要从http://membres.multimania.fr/marat/delphi/python.htm 下载Python4Delphi 的installer, 它最高仅支持python 2.3.

----------------------------   
Step2.  将 P4D 的定义文件加到 project.dpr
----------------------------
 在Delphi project.dpr, 在uses之前,加上{$I Definition.Inc}
 
 
----------------------------
Step3. 使用pythonengince 等组件
----------------------------
设置 pythonengince 组件的属性.
   UseLastKnownVersion=False
   DLLName='python27'
   DllPath= 'c:\WINDOWS\system32'   
   
        
----------------------------
Step4. 发布应用前, 需解决run as administrator问题,
----------------------------
(a)  需要 Microsoft.VC90.CRT 和 Microsoft.Windows.Common-Controls 信息作为资源加到delphi project中, 否则加载python的 c-extensions 模块会报错.

(b)创建 XP_UAC.manifest 文件, 内容见后.

(c)创建 XP_UAC.rc 文件, 内容:
1 24 XP_UAC.manifest
其中: 1-代表资源编号,  24-资源类型为 RTMAINIFEST , UAC.manifest为manifest文件名称

(d)使用delphi的brcc32将 XP_UAC.rc编译成 XP_UAC.res
命令: brcc32 XP_UAC.rc

(e)在Delphi project.dpr 源码
     (1)在{$R *.res} 后, 加上 {$R XP_UAC.res}

=================================
 部署python4delphi的应用程序
=================================
方式1. 和开发一样, 老老实实安装python以及python的第3方包, 然后你的delphi程序应该就能使用.
方式2. 像dreampie, 将python环境打包, 连同exe一起发布. 有专门的py2exe,cx_freeze等制作工具.

=================================
 XP_UAC.manifest  的内容
=================================
C:\WINDOWS\WinSxS 目录查找 Windows.Common-Controls 和 Microsoft.VC90.CRT, 如果能找到并且version一致,  只需修改 PyScripter 名字. 如果没有找到这两个文件, 需要到微软官网下载 Microsoft Visual C++ 2008 Redistributable Package, 并对比版本号和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的设置
=================================
关于PYTHONPATH的设置, 可在 TPythonEngine.OnSysPathInit 事件中, 将我们自己的path加到 PythonPATH 中.
如果代码中没有加, 我们需要修改注册表, 位置是 HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\PythonPath, 将我们的path加进去.
注意: TPythonEngine.OnPathInitialization 事件, 只有在注册表没有定义 PythonPath 才有用, 所以不推荐使用.

=================================
 python4delphi 资料汇总
=================================
python4delphi 最新源码
http://code.google.com/p/python4delphi/

Using P4D with Python 2.6, 3.0
http://code.google.com/p/python4delphi/wiki/P4DPython26

在Python 2.6, 3.0下使用P4D
http://www.cnblogs.com/babykick/archive/2011/03/25/1995970.html
   
Andy tips on python4delphi
http://www.atug.com/andypatterns/pythonDelphiTalk.htm

使用P4D 编写Python Extension  
http://1000copy.itpub.net/post/10379/276310

Python For Delphi---更好地协同
http://www.cnblogs.com/GarfieldTom/archive/2013/01/14/2860206.html

python4delphi 使用的更多相关文章

  1. python4delphi 安装

    环境搭建: 目前p4d已经可以支持到XE7,可惜googlecode即将关闭,不知道作者是否会在github上继续更新. 因为此开源项目历史较久远,拿到源代码后可能还需要手动修改相关的文件引用,毕竟需 ...

  2. python4delphi import lxml pandas 出错的小结

    环境: 1.win10 64位 2.delphi xe8 3.python2.7 4.python4delphi  (svn 2015-03-21 发布的83版本号) 5.lxml 3.4.4(通过p ...

  3. Python4Delphi也是与VCL密切相关,所以才能相互调用,绝对有研究价值!

    Python4Delphi也是与VCL密切相关,所以才能相互调用,绝对有研究价值! http://www.cnblogs.com/GarfieldTom/archive/2013/01/17/2864 ...

  4. python4delphi 设置syspath

    详细看demo25的代码 These techniques are demonstrated in Demo25 in the examples folder of your Python for D ...

  5. python4delphi Python could not be properly initialized. We must quit.

    要用32位的DLL,不要用64位的dll Unable to load Python 2.7 dll with Delphi 2010 #6  Closed GoogleCodeExporter op ...

  6. 最想做的三个Delphi项目:Paint,IM,SQL,另外还有Smart,TMS,FMX,UML,FreePascal,Python4Delphi,Cheat Engine

    都是绝美项目- 如果有时间,要做的项目:0. 整整5个Cloud项目(可带来商业收益,其中还包括手机发送, S/D/N/L/NetDriver)1. Heidi/front/SQLITE STUDIO ...

  7. 调用python 报R6034 错误

    R6034 指的是:"An application has made an attempt to load the C runtime library incorrectly. Please ...

随机推荐

  1. IIS配置错误信息输出

    Asp.net: 一.通过 IIS 配置 1.打开IIS管理器,或按住 WIN + R 打开命令行输入 inetmgr 打开 IIS 管理 2.左边目录选择目标站点,在右边 IIS 块中双击 “错误页 ...

  2. TYVJ1982 武器分配

    描述     后勤部队运来一批武器(机枪和盔甲).你要把这些武器分配给手下的marine们(每人一部机枪,一套盔甲).可是问题来了...    这些武器的型号不相同(武器是由出价最低的承包商制造的), ...

  3. C#关闭窗口代码

    if (MessageBox.Show("请您确认是否退出(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBox ...

  4. HDU 1598 find the most comfortable road(最小生成树之Kruskal)

    题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX ...

  5. STM8L --- External interrupt

    note 1:  Several interrupts can be pending at the same time. When an interrupt request is not servic ...

  6. ES6之模版字符串

    ES6之模版字符串 最近在项目中使用了ES6的模版字符串,在这里加以总结. 1.之前我们也可以使用JavaScript输出模版字符串,通常是下面这样的: $("#result"). ...

  7. php删除指定目录所有文件

    <?php /** * 删除指定文件目录下的所有文件 * @param str $dir 指定文件路径: 如:K:/wamp/www/test * return boole *--------- ...

  8. JavaWeb---总结(五)Http协议

    一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...

  9. CookContainer 序列化保存

    using System;using System.Collections;using System.Globalization;using System.IO;using System.Net;us ...

  10. idea community 配置已有的scala工程