Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkPythonHelper.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.
10 
11 ============================================================================*/
12 
13 #ifndef mitkPythonHelper_h
14 #define mitkPythonHelper_h
15 
16 #include <cassert>
17 
18 #include <mitkFileSystem.h>
20 
21 #define MITK_PYTHON_LIBRARY_FILENAME "libpython3.12.so"
22 
24 {
25  // DO NOT EDIT THIS FILE DIRECTLY.
26  // This header is auto-generated from mitkPythonHelper.h.in by CMake.
27  // To make changes, modify mitkPythonHelper.h.in instead.
28 
32 
34  MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvPath(const std::string& name);
35  MITKPYTHONHELPER_EXPORT bool VirtualEnvExists(const std::string& name);
36 
37  // Path to the Python interpreter inside the named virtual environment, or an
38  // empty path if the environment or its interpreter is missing. Use this for
39  // short-lived subprocesses that must run with the venv's own interpreter
40  // rather than the embedded one.
41  MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvExecutablePath(const std::string& name);
42 
43  // Path to a named console script (entry point) inside the named virtual
44  // environment: bin/<scriptName> on POSIX, Scripts/<scriptName>.exe on Windows
45  // (e.g. GetVirtualEnvScriptPath(name, "TotalSegmentator")). Returns an empty
46  // path only if the environment location cannot be resolved; the script file
47  // itself is not checked for existence, so the caller decides how to handle a
48  // missing script.
49  MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvScriptPath(const std::string& name, const std::string& scriptName);
50 
51  MITKPYTHONHELPER_EXPORT fs::path CreateVirtualEnv(const std::string& name);
52  MITKPYTHONHELPER_EXPORT bool ActivateVirtualEnv(const std::string& name);
53  MITKPYTHONHELPER_EXPORT bool ActivateVirtualEnv(const fs::path& path);
54  MITKPYTHONHELPER_EXPORT bool RemoveVirtualEnv(const std::string& name);
55  MITKPYTHONHELPER_EXPORT bool RemoveVirtualEnv(const fs::path& path);
56 
57  // Returns true if any shared library (.dll/.so/.dylib/.pyd) currently
58  // loaded into this process originates from the given virtual environment
59  // directory. RemoveVirtualEnv on such a venv would partial-fail on Windows
60  // (locked files) and on POSIX would unlink files still in use.
61  //
62  // Note: only modules loaded into THIS process are considered. A virtual
63  // environment in use by another running MITK instance cannot be detected.
66 
67  // String-literal overloads. Without these, calls like ActivateVirtualEnv("foo")
68  // are ambiguous because const char* converts equally well to both std::string
69  // and fs::path; an exact-match const char* overload disambiguates.
70  //
71  // \pre name != nullptr.
72  inline bool ActivateVirtualEnv(const char* name)
73  {
74  assert(name != nullptr);
75  return ActivateVirtualEnv(std::string(name));
76  }
77 
78  inline bool RemoveVirtualEnv(const char* name)
79  {
80  assert(name != nullptr);
81  return RemoveVirtualEnv(std::string(name));
82  }
83 
84  inline bool IsAnyVirtualEnvModuleLoaded(const char* name)
85  {
86  assert(name != nullptr);
87  return IsAnyVirtualEnvModuleLoaded(std::string(name));
88  }
89 }
90 
91 #endif
#define MITKPYTHONHELPER_EXPORT
Portability header that provides a unified namespace alias for the C++ filesystem library.
MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvPath(const std::string &name)
MITKPYTHONHELPER_EXPORT fs::path GetLibraryPath()
MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvExecutablePath(const std::string &name)
MITKPYTHONHELPER_EXPORT fs::path GetExecutablePath()
MITKPYTHONHELPER_EXPORT bool ActivateVirtualEnv(const std::string &name)
MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvBasePath()
MITKPYTHONHELPER_EXPORT fs::path GetVirtualEnvScriptPath(const std::string &name, const std::string &scriptName)
MITKPYTHONHELPER_EXPORT bool IsAnyVirtualEnvModuleLoaded(const std::string &name)
MITKPYTHONHELPER_EXPORT fs::path CreateVirtualEnv(const std::string &name)
MITKPYTHONHELPER_EXPORT bool RemoveVirtualEnv(const std::string &name)
MITKPYTHONHELPER_EXPORT bool VirtualEnvExists(const std::string &name)
MITKPYTHONHELPER_EXPORT fs::path GetHomePath()