Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
Medical Imaging Interaction Toolkit
QmitkSetupVirtualEnvUtil.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.s
10 
11 ============================================================================*/
12 
13 #ifndef QmitkSetupVirtualEnvUtil_h_Included
14 #define QmitkSetupVirtualEnvUtil_h_Included
15 
16 #include "mitkLog.h"
17 #include "mitkProcessExecutor.h"
19 #include <QString>
20 #include <functional>
21 
27 {
28 public:
29  using CallbackType = void (*)(itk::Object *, const itk::EventObject &, void *);
30 
31  QmitkSetupVirtualEnvUtil(const QString& baseDir);
33 
42  bool SetupVirtualEnv(const QString &venvName,
43  const QStringList &packages,
44  std::function<bool()> validator,
45  CallbackType printCallback,
46  const QString &torchVersion = "");
47 
54  virtual QString GetVirtualEnvPath();
55 
66  void PipInstall(const std::string &library,
67  const std::string &workingDir,
68  CallbackType callback,
69  const std::string &command = "pip3");
70 
78  void PipInstall(const std::string &library, CallbackType callback,
79  const std::string &command = "pip3");
80 
81 
91  void ExecutePython(const std::string &args,
92  const std::string &pythonPath,
93  CallbackType callback,
94  const std::string &command = "python");
95 
104  void ExecutePython(const std::string &args, CallbackType callback,
105  const std::string &command = "python");
106 
116  void InstallPytorch(const QString &workingDir, CallbackType callback, const QString &torchVersion = "");
117 
122  void InstallPytorch(const QString& torchVersion = "");
123 
128  void InstallPytorch(CallbackType callback, const QString& torchVersion = "");
129 
130 
136  QString& GetBaseDir();
137 
143  QString& GetSystemPythonPath();
144 
150  QString& GetPythonPath();
151 
157  QString& GetPipPath();
158 
164  void SetSystemPythonPath(const QString& path);
165 
171  void SetPythonPath(const QString& path);
172 
178  void SetPipPath(const QString& path);
179 
185  void SetVirtualEnvPath(const QString &path);
186 
194  bool IsPythonPath(const QString &pythonPath);
195 
200  static bool IsVenvInstalled(const QString &pythonPath);
201 
206  static QString GetPipPackageVersion(const QString &pythonPath, const QString &packageName);
207 
213  static void PrintProcessEvent(itk::Object *, const itk::EventObject &e, void *);
214 
220  static std::pair<QString, QString> GetExactPythonPath(const QString &pyEnv);
221 
226  static QStringList AutoParsePythonPaths();
227 
228 private:
229  QString m_PythonPath;
230  QString m_PipPath;
231  QString m_BaseDir;
232  QString m_venvPath;
233  QString m_SysPythonPath;
234 };
235 #endif
mitk::PythonHelper::GetVirtualEnvPath
MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvPath(const std::string &name)
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkSetupVirtualEnvUtil
Abstract Class to Setup a python virtual environment and pip install required packages....
Definition: QmitkSetupVirtualEnvUtil.h:26
mitkProcessExecutor.h
mitkLog.h
MitkSegmentationUIExports.h
QmitkSetupVirtualEnvUtil::CallbackType
void(*)(itk::Object *, const itk::EventObject &, void *) CallbackType
Definition: QmitkSetupVirtualEnvUtil.h:29