1818#define TOMVIZ_DATA_INSTALL_DIR "@tomviz_data_install_dir@/Data"
1919#define TOMVIZ_PATH_FROM_EXE_TO_PYTHON_INSTALL_DIR "@tomviz_path_from_exe_to_python_install_dir@"
2020
21+ #include <cstdlib>
2122#include <string>
2223#include <vtksys/SystemTools.hxx>
2324
2425#include "PythonUtilities.h"
2526
27+ // Used for determining paths to the site packages
28+ static const std ::string PYTHON_VER = "3." PYTHON_VERSION_MINOR ;
29+
2630namespace tomviz {
2731void PythonAppInitPrependPythonPath (const std ::string & dir )
2832{
@@ -62,6 +66,16 @@ void PythonAppInitPrependPathWindows(const std::string& exe_dir)
6266 PythonAppInitPrependPythonPath (exe_dir +
6367 "/../lib/paraview/site-packages/vtk" );
6468 PythonAppInitPrependPythonPath (exe_dir + "/../lib/itk/site-packages" );
69+ PythonAppInitPrependPythonPath (exe_dir +
70+ "/../lib/python" +
71+ PYTHON_VER +
72+ "/site-packages" );
73+ }
74+
75+ // Prepend conda prefix site packages if available
76+ std ::string conda_prefix = std ::getenv ("CONDA_PREFIX" );
77+ if (!conda_prefix .empty ()) {
78+ PythonAppInitPrependPythonPath (conda_prefix + "/Lib/site-packages" );
6579 }
6680}
6781
@@ -87,14 +101,27 @@ void PythonAppInitPrependPathLinux(const std::string& exe_dir)
87101 // since exe_dir in <PREFiX>/bin, we do a /../
88102 PythonAppInitPrependPythonPath (exe_dir + "/../" TOMVIZ_PYTHON_INSTALL_DIR );
89103
90- // Add the location for numpy and scipy
91- PythonAppInitPrependPythonPath (exe_dir + "/../lib/python3.7/site-packages" );
104+ auto python_path = exe_dir + "/../lib/python" + PYTHON_VER ;
92105
93- // Add root python3.7 dir
94- PythonAppInitPrependPythonPath (exe_dir + "/../lib/python3.7" );
106+ // Add root python dir
107+ PythonAppInitPrependPythonPath (python_path );
108+
109+ // Add the location for numpy and scipy
110+ PythonAppInitPrependPythonPath (python_path + "/site-packages" );
95111
96112 // Add the location of python .so libraries
97- PythonAppInitPrependPythonPath (exe_dir + "/../lib/python3.7/lib-dynload" );
113+ PythonAppInitPrependPythonPath (python_path + "/lib-dynload" );
114+ }
115+
116+ // Prepend conda prefix site packages if available
117+ std ::string conda_prefix = std ::getenv ("CONDA_PREFIX" );
118+ if (!conda_prefix .empty ()) {
119+ PythonAppInitPrependPythonPath (
120+ conda_prefix +
121+ "/lib/python" +
122+ PYTHON_VER +
123+ "/site-packages"
124+ );
98125 }
99126}
100127
@@ -119,11 +146,24 @@ void PythonAppInitPrependPathOsX(const std::string& exe_dir)
119146 // we don't add anything for ParaView since, ParaView takes care of that.
120147 PythonAppInitPrependPythonPath (exe_dir + "/../Libraries/" );
121148 PythonAppInitPrependPythonPath (exe_dir +
122- "/../Libraries/python3.7/site-packages" );
149+ "/../Libraries/python" +
150+ PYTHON_VER +
151+ "/site-packages" );
123152 PythonAppInitPrependPythonPath (exe_dir + "/../Python" );
124153 PythonAppInitPrependPythonPath (exe_dir + "/../Python/lib-dynload" );
125154 PythonAppInitPrependPythonPath (exe_dir + "/../Python/site-packages" );
126155 }
156+
157+ // Prepend conda prefix site packages if available
158+ std ::string conda_prefix = std ::getenv ("CONDA_PREFIX" );
159+ if (!conda_prefix .empty ()) {
160+ PythonAppInitPrependPythonPath (
161+ conda_prefix +
162+ "/lib/python" +
163+ PYTHON_VER +
164+ "/site-packages"
165+ );
166+ }
127167}
128168
129169bool isApplicationBundle (const std ::string & exeDir )
@@ -147,7 +187,7 @@ std::string bundlePythonPath(const std::string& exeDir)
147187#elif defined(_WIN32 )
148188 return "" ;
149189#else
150- return exeDir + "/../lib/python3.7" ;
190+ return exeDir + "/../lib/python" + PYTHON_VER ;
151191#endif
152192}
153193
0 commit comments