我无法在Python 2.6下使用Delphi中的Python

0 投票
2 回答
1127 浏览
提问于 2025-04-16 13:54

我的环境是 Delphi 7 和 Python 2.6.6,并且安装了 Python for Delphi。

但是当我运行一个测试应用时,出现了运行时错误。

Microsoft Visual C++ Runtime Library
Runtime Error!
program:E:\programming\delphi\p4dtest\dd\project1.exe

This application has requeste, the Runtime to terminate it in an unusual way.  
Please contact the application's support team for more information.

test.py:

import ctypes
print 'hello'

Delphi 应用的主程序:

procedure TForm1.Button1Click(Sender: TObject);
begin
      PyExeFile('test.py', PE);    
end;

如果我去掉 "import ctypes" 这一行,程序就能正常运行,但如果导入了 ctypes,就会出错。

我在网上查了一下,发现了一个相关的问题:http://code.google.com/p/python4delphi/wiki/P4DPython26

根据文章的内容,我编译了 res 文件,并把这个 res 文件、Microsoft.VC90.CRT.manifest 以及 msvcr90.dll 放到了项目文件夹里,还在项目文件中添加了 XP_UAC.RES,但我还是遇到了错误。然后我重新安装了 Microsoft Visual C++ 2008 SP1 Redistributable Package,但似乎这不是问题所在。有没有人成功在 Python 2.6 下使用 P4D 的,请告诉我该怎么做。

==================================
现在我通过阅读 P4D 官方网站上的问题,自己解决了这个问题:

1、In the pythonengine property tab

‍keep set  “UseLastKnownVersion” to True

‍keep ‍set   "DLLName"  to  python26

2、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.

顺便说一下,我不是想让大家困惑我的问题,如果造成了困扰,我很抱歉,所以如果你没有自己尝试过,请不要随意引用别人的问题。

2 个回答

1

我试过babykick的解决方案,但一直收到错误信息:无法加载 python25.dll

以下方法对我有效。(使用的是 delphi7、python26 和 windows xp sp3)

打开 TPythonEngine 的属性选项卡,然后进行以下修改:

  • DllName : python26.dll
  • DllPath : c:\windows\system32\
  • UseLastknownVersion : false
1

可能我之前没有把我的问题说清楚。现在我通过查看P4D官方网站上的问题讨论,自己解决了这个问题。

1、In the pythonengine property tab

‍keep set  “UseLastKnownVersion” to True

‍keep ‍set   "DLLName"  to  python26

2、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  

撰写回答