@@ -13,6 +13,8 @@ public class UnrealEnginePython : ModuleRules
1313 //private string pythonHome = "C:/Program Files/Python36";
1414 // this is an example for Homebrew on Mac
1515 //private string pythonHome = "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/";
16+ // on Linux an include;libs syntax is expected:
17+ //private string pythonHome = "/usr/local/include/python3.6;/usr/local/lib/libpython3.6.so"
1618
1719
1820 private string [ ] windowsKnownPaths =
@@ -30,6 +32,44 @@ public class UnrealEnginePython : ModuleRules
3032 "/Library/Frameworks/Python.framework/Versions/2.7" ,
3133 } ;
3234
35+ private string [ ] linuxKnownIncludesPaths =
36+ {
37+ "/usr/local/include/python3.6" ,
38+ "/usr/local/include/python3.6m" ,
39+ "/usr/local/include/python3.5" ,
40+ "/usr/local/include/python3.5m" ,
41+ "/usr/local/include/python2.7" ,
42+ "/usr/include/python3.6" ,
43+ "/usr/include/python3.6m" ,
44+ "/usr/include/python3.5" ,
45+ "/usr/include/python3.5m" ,
46+ "/usr/include/python2.7" ,
47+ } ;
48+
49+ private string [ ] linuxKnownLibsPaths =
50+ {
51+ "/usr/local/lib/libpython3.6.so" ,
52+ "/usr/local/lib/libpython3.6m.so" ,
53+ "/usr/local/lib/x86_64-linux-gnu/libpython3.6.so" ,
54+ "/usr/local/lib/x86_64-linux-gnu/libpython3.6m.so" ,
55+ "/usr/local/lib/libpython3.5.so" ,
56+ "/usr/local/lib/libpython3.5m.so" ,
57+ "/usr/local/lib/x86_64-linux-gnu/libpython3.5.so" ,
58+ "/usr/local/lib/x86_64-linux-gnu/libpython3.5m.so" ,
59+ "/usr/local/lib/libpython2.7.so" ,
60+ "/usr/local/lib/x86_64-linux-gnu/libpython2.7.so" ,
61+ "/usr/lib/libpython3.6.so" ,
62+ "/usr/lib/libpython3.6m.so" ,
63+ "/usr/lib/x86_64-linux-gnu/libpython3.6.so" ,
64+ "/usr/lib/x86_64-linux-gnu/libpython3.6m.so" ,
65+ "/usr/lib/libpython3.5.so" ,
66+ "/usr/lib/libpython3.5m.so" ,
67+ "/usr/lib/x86_64-linux-gnu/libpython3.5.so" ,
68+ "/usr/lib/x86_64-linux-gnu/libpython3.5m.so" ,
69+ "/usr/lib/libpython2.7.so" ,
70+ "/usr/lib/x86_64-linux-gnu/libpython2.7.so" ,
71+ } ;
72+
3373 public UnrealEnginePython ( TargetInfo Target )
3474 {
3575
@@ -140,15 +180,26 @@ public UnrealEnginePython(TargetInfo Target)
140180 }
141181 else if ( Target . Platform == UnrealTargetPlatform . Linux )
142182 {
143- if ( pythonHome == "python35 " )
183+ if ( pythonHome == "" )
144184 {
145- PublicIncludePaths . Add ( "/usr/include/python3.5m" ) ;
146- PublicAdditionalLibraries . Add ( "/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so" ) ;
185+ string includesPath = DiscoverLinuxPythonIncludesPath ( ) ;
186+ if ( includesPath == null )
187+ {
188+ throw new System . Exception ( "Unable to find Python includes, please add a search path to linuxKnownIncludesPaths" ) ;
189+ }
190+ string libsPath = DiscoverLinuxPythonLibsPath ( ) ;
191+ if ( libsPath == null )
192+ {
193+ throw new System . Exception ( "Unable to find Python libs, please add a search path to linuxKnownLibsPaths" ) ;
194+ }
195+ PublicIncludePaths . Add ( includesPath ) ;
196+ PublicAdditionalLibraries . Add ( libsPath ) ;
147197 }
148- else if ( pythonHome == "python27" )
198+ else
149199 {
150- PublicIncludePaths . Add ( "/usr/include/python2.7" ) ;
151- PublicAdditionalLibraries . Add ( "/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so" ) ;
200+ string [ ] items = pythonHome . Split ( ';' ) ;
201+ PublicIncludePaths . Add ( items [ 0 ] ) ;
202+ PublicAdditionalLibraries . Add ( items [ 1 ] ) ;
152203 }
153204 Definitions . Add ( string . Format ( "UNREAL_ENGINE_PYTHON_ON_LINUX" ) ) ;
154205 }
@@ -180,6 +231,31 @@ private string DiscoverPythonPath(string[] knownPaths)
180231 return "" ;
181232 }
182233
234+ private string DiscoverLinuxPythonIncludesPath ( )
235+ {
236+ foreach ( string path in linuxKnownIncludesPaths )
237+ {
238+ string headerFile = Path . Combine ( path , "Python.h" ) ;
239+ if ( File . Exists ( headerFile ) )
240+ {
241+ return path ;
242+ }
243+ }
244+ return null ;
245+ }
246+
247+ private string DiscoverLinuxPythonLibsPath ( )
248+ {
249+ foreach ( string path in linuxKnownLibsPaths )
250+ {
251+ if ( File . Exists ( path ) )
252+ {
253+ return path ;
254+ }
255+ }
256+ return null ;
257+ }
258+
183259 private string GetMacPythonLibFile ( string basePath )
184260 {
185261 // first try with python3
0 commit comments