122 std::filesystem::path
const& venv_path)
124 namespace fs = std::filesystem;
126 std::vector<fs::path> alternatives;
127 fs::path
const lib_path = venv_path /
"lib";
129 if (!fs::exists(lib_path) || !fs::is_directory(lib_path))
135 for (
auto const& entry : fs::directory_iterator(lib_path))
137 if (!entry.is_directory())
142 std::string
const dirname = entry.path().filename().string();
143 if (!dirname.starts_with(
"python"))
148 fs::path
const candidate = entry.path() /
"site-packages";
149 if (fs::exists(candidate) && fs::is_directory(candidate))
151 alternatives.push_back(candidate);
160 std::filesystem::path
const& venv_path,
int const emb_major,
163 namespace fs = std::filesystem;
168 auto const venv_version = getPythonVersionFromVenv(venv_path);
169 if (!venv_version.has_value())
172 "Failed to determine Python version from virtual environment at "
177 if (venv_version->first != emb_major || venv_version->second != emb_minor)
180 "Python version mismatch: embedded interpreter is {}.{}, but "
181 "virtual environment at '{}' uses {}.{}.",
182 emb_major, emb_minor, venv_path.string(), venv_version->first,
183 venv_version->second);
186 fs::path
const site_packages = venv_path /
"Lib" /
"site-packages";
194 fs::path
const site_packages = venv_path /
"lib" /
195 (
"python" + std::to_string(emb_major) +
"." +
196 std::to_string(emb_minor)) /
200 if (!fs::exists(site_packages))
207 if (!alternatives.empty())
209 std::string alternative_paths;
210 for (std::size_t i = 0; i < alternatives.size(); ++i)
214 alternative_paths +=
", ";
216 alternative_paths +=
"'" + alternatives[i].string() +
"'";
220 "Expected site-packages directory '{}' was not found. "
221 "Found other site-packages directory/directories: {}. This "
222 "may indicate a Python version mismatch between the embedded "
223 "interpreter {}.{} and the virtual environment.",
224 site_packages.string(), alternative_paths, emb_major,
228 OGS_FATAL(
"site-packages directory not found at '{}'",
229 site_packages.string());
232 return site_packages;