Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5c067f

Browse files
committed
python 2.7.11 support.
1 parent16ce677 commite5c067f

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

‎PythonForDelphi/Components/Sources/Core/PythonEngine.pas‎

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ EPyWindowsError = class (EPyOSError);
13791379

13801380
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
13811381
[ComponentPlatformsAttribute(pidWin32or pidWin64)]
1382-
{$IFEND}
1382+
{$ENDIF}
13831383
TPythonInputOutput =class(TComponent)
13841384
protected
13851385
FMaxLines : Integer;
@@ -1684,6 +1684,9 @@ TPythonInterface=class(TDynamicDll)
16841684
PyArg_Parse: function( args: PPyObject; format: PAnsiChar{;....}) : Integer; cdecl varargs;
16851685
PyArg_ParseTuple: function( args: PPyObject; format: PAnsiChar{;...}): Integer; cdecl varargs;
16861686
Py_BuildValue: function( format: PAnsiChar{;...}): PPyObject; cdecl varargs;
1687+
1688+
Py_SetPythonHome: procedure( home: PAnsiChar); cdecl;
1689+
16871690
Py_Initialize: procedure; cdecl;
16881691
Py_Exit: procedure( RetVal: Integer); cdecl;
16891692
PyEval_GetBuiltins: function: PPyObject; cdecl;
@@ -2120,7 +2123,7 @@ TPythonTraceback = class
21202123

21212124
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
21222125
[ComponentPlatformsAttribute(pidWin32or pidWin64)]
2123-
{$IFEND}
2126+
{$ENDIF}
21242127
TPythonEngine =class(TPythonInterface)
21252128
private
21262129
FInitScript: TStrings;
@@ -2588,7 +2591,7 @@ TErrors = class(TCollection)
25882591

25892592
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
25902593
[ComponentPlatformsAttribute(pidWin32or pidWin64)]
2591-
{$IFEND}
2594+
{$ENDIF}
25922595
TPythonModule =class(TMethodsContainer)
25932596
protected
25942597
FModuleName : AnsiString;
@@ -2853,7 +2856,7 @@ TTypeServices = class(TPersistent)
28532856
// that creates instances of itself.
28542857
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
28552858
[ComponentPlatformsAttribute(pidWin32or pidWin64)]
2856-
{$IFEND}
2859+
{$ENDIF}
28572860
TPythonType =class(TGetSetContainer)
28582861
protected
28592862
FType : PyTypeObject;
@@ -2941,7 +2944,7 @@ TPythonType = class(TGetSetContainer)
29412944

29422945
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
29432946
[ComponentPlatformsAttribute(pidWin32or pidWin64)]
2944-
{$IFEND}
2947+
{$ENDIF}
29452948
TPythonDelphiVar =class( TEngineClient )
29462949
protected
29472950
FModule : AnsiString;
@@ -3098,6 +3101,7 @@ function PyType_HasFeature(AType : PPyTypeObject; AFlag : Integer) : Boolean;
30983101
{$IFDEF MSWINDOWS}
30993102
functionIsPythonVersionRegistered(PythonVersion : string;
31003103
out InstallPath: string; out AllUserInstall: Boolean) : Boolean;
3104+
functionGetPythonHome(): string;
31013105
{$ENDIF}
31023106
(*
31033107
Mask FPU Excptions - Useful for importing SciPy and other Python libs
@@ -3743,6 +3747,9 @@ procedure TPythonInterface.MapDll;
37433747
PyArg_ParseTuple :=Import('PyArg_ParseTuple');
37443748
Py_BuildValue :=Import('Py_BuildValue');
37453749
Py_Initialize :=Import('Py_Initialize');
3750+
Py_SetPythonHome :=Import('Py_SetPythonHome');
3751+
3752+
37463753
PyDict_New :=Import('PyDict_New');
37473754
PyDict_SetItemString :=Import('PyDict_SetItemString');
37483755
PyModule_GetDict :=Import('PyModule_GetDict');
@@ -4766,6 +4773,7 @@ procedure TPythonEngine.Initialize;
47664773

47674774
var
47684775
i : Integer;
4776+
PythonVersion: string;
47694777
begin
47704778
if Assigned(gPythonEngine)then
47714779
raise Exception.Create('There is already one instance of TPythonEngine running' );
@@ -4795,6 +4803,11 @@ procedure TPythonEngine.Initialize;
47954803
end
47964804
end;
47974805
AssignPyFlags;
4806+
PythonVersion := Format('%s.%s', [IntToStr(gPythonEngine.FMajorVersion), IntToStr(gPythonEngine.FMinorVersion)]);
4807+
if PythonVersion ='2.7'then
4808+
Py_SetPythonHome(PAnsiChar(AnsiString(GetPythonHome())));
4809+
//Py_SetPythonHome('C:\Python27_32');
4810+
//end;
47984811
Py_Initialize;
47994812
FInitialized := True;
48004813
FIORedirected := False;
@@ -9714,7 +9727,7 @@ function IsPythonVersionRegistered(PythonVersion : string;
97149727
try
97159728

97169729
// 3.5
9717-
key := Format('\Software\Python\PythonCore\%s\InstallPath', [IfThen(PythonVersionFloat <3.5, PythonVersion, PythonVersion{$IFDEF WIN32}+'-32'{$ENDIF})]);// python 3.5 only 32bit
9730+
key := Format('\Software\Python\PythonCore\%s\InstallPath', [IfThen(PythonVersionFloat <3.5, PythonVersion, PythonVersion{$IFDEF WIN32}+'-32'{$ENDIF})]);
97189731

97199732
with TRegistry.Create(KEY_READandnot KEY_NOTIFY)do
97209733
try
@@ -9723,7 +9736,7 @@ function IsPythonVersionRegistered(PythonVersion : string;
97239736

97249737
if KeyExists(key)thenbegin
97259738
AllUserInstall := True;
9726-
if PythonVersionFloat >=3.5then
9739+
if(PythonVersionFloat >=3.5)then
97279740
if OpenKey(Key, False)then
97289741
InstallPath := ReadString('');// python version 3.5 up
97299742
Result := True;
@@ -9738,7 +9751,7 @@ function IsPythonVersionRegistered(PythonVersion : string;
97389751
ifnot AllUserInstallthen
97399752
with TRegistry.Create(KEY_READandnot KEY_NOTIFY)do
97409753
try
9741-
RootKey := HKEY_CURRENT_USER;
9754+
RootKey :=IfThen(PythonVersionFloat <3.5, HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER);
97429755
if OpenKey(Key, False)thenbegin
97439756
InstallPath := ReadString('');
97449757
Result := True;
@@ -9747,6 +9760,25 @@ function IsPythonVersionRegistered(PythonVersion : string;
97479760
Free;
97489761
end;
97499762
end;
9763+
9764+
9765+
// for only 2.7
9766+
functionGetPythonHome(): string;
9767+
var
9768+
temp: Boolean;
9769+
key: string;
9770+
begin
9771+
with TRegistry.Create(KEY_READandnot KEY_NOTIFY)do
9772+
try
9773+
RootKey := HKEY_LOCAL_MACHINE;
9774+
key := Format('\Software\Python\PythonCore\%s\InstallPath', ['2.7']);
9775+
if OpenKey(Key, False)then
9776+
Result := ReadString('');
9777+
finally
9778+
Free;
9779+
end;
9780+
end;
9781+
97509782
{$ENDIF}
97519783

97529784
end.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp