Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
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 
26 {
27 public:
28  using CallbackType = void (*)(itk::Object *, const itk::EventObject &, void *);
29 
30  QmitkSetupVirtualEnvUtil(const QString& baseDir);
32 
37  virtual bool SetupVirtualEnv(const QString& venvName) = 0;
38 
45  virtual QString GetVirtualEnvPath();
46 
57  void PipInstall(const std::string &library,
58  const std::string &workingDir,
59  CallbackType callback,
60  const std::string &command = "pip3");
61 
69  void PipInstall(const std::string &library, CallbackType callback,
70  const std::string &command = "pip3");
71 
72 
82  void ExecutePython(const std::string &args,
83  const std::string &pythonPath,
84  CallbackType callback,
85  const std::string &command = "python");
86 
95  void ExecutePython(const std::string &args, CallbackType callback,
96  const std::string &command = "python");
97 
106  void InstallPytorch(const std::string &workingDir, CallbackType callback);
107 
112  void InstallPytorch();
113 
118  void InstallPytorch(CallbackType callback);
119 
120 
126  QString& GetBaseDir();
127 
133  QString& GetSystemPythonPath();
134 
140  QString& GetPythonPath();
141 
147  QString& GetPipPath();
148 
154  void SetSystemPythonPath(const QString& path);
155 
161  void SetPythonPath(const QString& path);
162 
168  void SetPipPath(const QString& path);
169 
175  void SetVirtualEnvPath(const QString &path);
176 
184  bool IsPythonPath(const QString &pythonPath);
185 
190  static bool IsVenvInstalled(const QString &pythonPath);
191 
196  static QString GetPipPackageVersion(const QString &pythonPath, const QString &packageName);
197 
203  static void PrintProcessEvent(itk::Object *, const itk::EventObject &e, void *);
204 
210  static std::pair<QString, QString> GetExactPythonPath(const QString &pyEnv);
211 
212 private:
213  QString m_PythonPath;
214  QString m_PipPath;
215  QString m_BaseDir;
216  QString m_venvPath;
217  QString m_SysPythonPath;
218 };
219 #endif
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:25
mitkProcessExecutor.h
mitkLog.h
MitkSegmentationUIExports.h
QmitkSetupVirtualEnvUtil::CallbackType
void(*)(itk::Object *, const itk::EventObject &, void *) CallbackType
Definition: QmitkSetupVirtualEnvUtil.h:28