Skip to content

Commit cbf68a6

Browse files
committed
Attempting to work around this error on windows:
2025-09-21T07:31:06.0673422Z python.exe found in: C:\Miniconda\envs\shapeworks 2025-09-21T07:31:06.0673897Z [2025-09-21 07:30:08.678] [info] Running Python File: python_embedded.py 2025-09-21T07:31:06.0674467Z unknown file: error: C++ exception with description "ImportError: Error importing numpy: you should not try to import numpy from 2025-09-21T07:31:06.0675041Z its source directory; please exit the numpy source tree, and relaunch 2025-09-21T07:31:06.0675371Z your python interpreter from there.
1 parent 38addb2 commit cbf68a6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Libs/Optimize/Optimize.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,28 @@ bool Optimize::Run() {
7777

7878
if (m_python_filename != "") {
7979
#ifdef _WIN32
80+
// Save current directory
81+
char original_dir[MAX_PATH];
82+
_getcwd(original_dir, MAX_PATH);
83+
8084
// need to set PYTHONHOME to the same directory as python.exe on Windows
8185
std::string found_path = find_in_path("python.exe");
8286
if (found_path != "") {
8387
std::cerr << "python.exe found in: " << found_path << "\n";
8488
_putenv_s("PYTHONHOME", found_path.c_str());
8589
}
90+
91+
// Change to safe directory for Python init
92+
_chdir("C:\\");
8693
#endif
8794

8895
py::initialize_interpreter();
8996

97+
#ifdef _WIN32
98+
// Restore original directory
99+
_chdir(original_dir);
100+
#endif
101+
90102
auto dir = m_python_filename;
91103

92104
auto filename = dir.substr(dir.find_last_of("/") + 1);

0 commit comments

Comments
 (0)