121 std::filesystem::path
const& venv_path)
123 namespace fs = std::filesystem;
125 std::vector<fs::path> alternatives;
126 fs::path
const lib_path = venv_path /
"lib";
128 if (!fs::exists(lib_path) || !fs::is_directory(lib_path))
134 for (
auto const& entry : fs::directory_iterator(lib_path))
136 if (!entry.is_directory())
141 std::string
const dirname = entry.path().filename().string();
142 if (!dirname.starts_with(
"python"))
147 fs::path
const candidate = entry.path() /
"site-packages";
148 if (fs::exists(candidate) && fs::is_directory(candidate))
150 alternatives.push_back(candidate);
159 std::filesystem::path
const& venv_path,
int const emb_major,
162 namespace fs = std::filesystem;
167 auto const venv_version = getPythonVersionFromVenv(venv_path);
168 if (!venv_version.has_value())
171 "Failed to determine Python version from virtual environment at "
176 if (venv_version->first != emb_major || venv_version->second != emb_minor)
179 "Python version mismatch: embedded interpreter is {}.{}, but "
180 "virtual environment at '{}' uses {}.{}.",
181 emb_major, emb_minor, venv_path.string(), venv_version->first,
182 venv_version->second);
185 fs::path
const site_packages = venv_path /
"Lib" /
"site-packages";
193 fs::path
const site_packages = venv_path /
"lib" /
194 (
"python" + std::to_string(emb_major) +
"." +
195 std::to_string(emb_minor)) /
199 if (!fs::exists(site_packages))
206 if (!alternatives.empty())
208 std::string alternative_paths;
209 for (std::size_t i = 0; i < alternatives.size(); ++i)
213 alternative_paths +=
", ";
215 alternative_paths +=
"'" + alternatives[i].string() +
"'";
219 "Expected site-packages directory '{}' was not found. "
220 "Found other site-packages directory/directories: {}. This "
221 "may indicate a Python version mismatch between the embedded "
222 "interpreter {}.{} and the virtual environment.",
223 site_packages.string(), alternative_paths, emb_major,
227 OGS_FATAL(
"site-packages directory not found at '{}'",
228 site_packages.string());
231 return site_packages;