# CMake executed by a Python script can't find the file which exists.

**URL:** https://discourse.cmake.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/13798
**Category:** Usage
**Tags:** os:linux, os:windows
**Created:** [March 23, 2025, 11:10am UTC](https://discourse.cmake.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/13798 "2025-03-23T11:10:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ay0ks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ay0ks/32/5430_2.png) [@ay0ks](https://discourse.cmake.org/u/ay0ks)
#### Post date: [March 23, 2025, 11:10am UTC](https://discourse.cmake.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/13798/1 "2025-03-23T11:10:33Z")

</div>

For some unclear reason the command executed by a Python script doesn’t work both in WSL and Windows, however works if I execute the command myself in a shell.

Script on GitHub Gist: [Project configurator script · GitHub](https://gist.github.com/ay0ks/30e28b5263241675e2c893518c0f07d6)

# Linux

Command line (executed by `python Configure.py -T Linux-x64`):

```auto
cmake \
  -S /mnt/c/Users/ay0ks/Workspace/Red \
  -B /mnt/c/Users/ay0ks/Workspace/Red/Destination/Build/Linux-x64-Linux-x64/GNU-14.2.1-GNU-2.44/Debug \
  -DCMAKE_TOOLCHAIN_FILE="/mnt/c/Users/ay0ks/Workspace/Red/Auxillary/Toolchains/Linux-x64.cmake" \
  -DCMAKE_BUILD_TYPE="Debug" \
  -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" \
  -DCMAKE_MAKE_PROGRAM=ninja \
  -GNinja

```

Result:

```auto
❯ python Configure.py -T Linux-x64
-- Identifying the compilation environment
 > project("Identify")
 > message("${CMAKE_C_COMPILER_ID} ~~~${CMAKE_C_COMPILER_VERSION}~~~ ${CMAKE_C_COMPILER_LINKER_ID}~~~${CMAKE_C_COMPILER_LINKER_VERSION}")
 > message("${CMAKE_CXX_COMPILER_ID} ~~~${CMAKE_CXX_COMPILER_VERSION}~~~ ${CMAKE_CXX_COMPILER_LINKER_ID}~~~${CMAKE_CXX_COMPILER_LINKER_VERSION}")
 > cmake -Wno-dev -S /tmp/tmp7q12ok5j -B /tmp/tmp7q12ok5j
-- Identified environment:
 @ C/CXX compiler vendor: GNU
 @ C/CXX compiler version: 14.2.1
 @ Linker vendor: GNU
 @ Lompiler version: 2.44
-- Destination directory:
 "../../Destination/Build/Linux-x64-Linux-x64/GNU-14.2.1-GNU-2.44/Debug"
-- Bootstrapping the compilation configuration
 > cmake -S /mnt/c/Users/ay0ks/Workspace/Red -B /mnt/c/Users/ay0ks/Workspace/Red/Destination/Build/Linux-x64-Linux-x64/GNU-14.2.1-GNU-2.44/Debug -DCMAKE_TOOLCHAIN_FILE="/mnt/c/Users/ay0ks/Workspace/Red/Auxillary/Toolchains/Linux-x64.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" -DCMAKE_MAKE_PROGRAM=ninja -GNinja
CMake Error at /usr/share/cmake/Modules/CMakeDetermineSystem.cmake:152 (message):
  Could not find toolchain file:
  "/mnt/c/Users/ay0ks/Workspace/Red/Auxillary/Toolchains/Linux-x64.cmake"
Call Stack (most recent call first):
  CMakeLists.txt:9 (project)

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

~/Workspace/Red/Auxillary/Scripts ········································································ 3s
❯

```

However, if I execute the command manually, it works like it should:

```auto
❯ cmake -S /mnt/c/Users/ay0ks/Workspace/Red -B /mnt/c/Users/ay0ks/Workspace/Red/Destination/Build/Linux-x64-Linux-x64/GNU-14.2.1-GNU-2.44/Debug -DCMAKE_TOOLCHAIN_FILE="/mnt/c/Users/ay0ks/Workspace/Red/Auxillary/Toolchains/Linux-x64.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" -DCMAKE_MAKE_PROGRAM=ninja -GNinja
-- The C compiler identification is Clang 19.1.7
-- The CXX compiler identification is Clang 19.1.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.6s)
-- Generating done (0.3s)
-- Build files have been written to: /home/ay0ks/Workspace/Red/Destination/Build/Linux-x64-Linux-x64/GNU-14.2.1-GNU-2.44/Debug

~/Workspace/Red/Auxillary/Scripts ···················································································································· 6s
❯

```

# Windows

Command line (executed by `python Configure.py -T Windows-x64`):

```auto
cmake \
  -S C:\Users\ay0ks\Workspace\Red \
  -B C:\Users\ay0ks\Workspace\Red\Destination\Build\Windows-x64-Windows-x64\MSVC-19.43.34808.0-MSVC-14.43.34808.0\Debug \
  -DCMAKE_TOOLCHAIN_FILE="C:\Users\ay0ks\Workspace\Red\Auxillary\Toolchains\Windows-x64.cmake" \
  -DCMAKE_BUILD_TYPE="Debug" \
  -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" \
  -DCMAKE_MAKE_PROGRAM=ninja \
  -GNinja

```

Result:

```auto
PS C:\Users\ay0ks\Workspace\Red\Auxillary\Scripts> python .\Configure.py -T Windows-x64
-- Identifying the compilation environment
 > project("Identify")
 > message("${CMAKE_C_COMPILER_ID} ~~~${CMAKE_C_COMPILER_VERSION}~~~ ${CMAKE_C_COMPILER_LINKER_ID}~~~${CMAKE_C_COMPILER_LINKER_VERSION}")
 > message("${CMAKE_CXX_COMPILER_ID} ~~~${CMAKE_CXX_COMPILER_VERSION}~~~ ${CMAKE_CXX_COMPILER_LINKER_ID}~~~${CMAKE_CXX_COMPILER_LINKER_VERSION}")
 > cmake -Wno-dev -S C:\Users\ay0ks\AppData\Local\Temp\tmp15a2x462 -B C:\Users\ay0ks\AppData\Local\Temp\tmp15a2x462
-- Identified environment:
 @ C/CXX compiler vendor: MSVC
 @ C/CXX compiler version: 19.43.34808.0
 @ Linker vendor: MSVC
 @ Lompiler version: 14.43.34808.0
-- Destination directory:
 "..\..\Destination\Build\Windows-x64-Windows-x64\MSVC-19.43.34808.0-MSVC-14.43.34808.0\Debug"
-- Bootstrapping the compilation configuration
 > cmake -S C:\Users\ay0ks\Workspace\Red -B C:\Users\ay0ks\Workspace\Red\Destination\Build\Windows-x64-Windows-x64\MSVC-19.43.34808.0-MSVC-14.43.34808.0\Debug -DCMAKE_TOOLCHAIN_FILE="C:\Users\ay0ks\Workspace\Red\Auxillary\Toolchains\Windows-x64.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" -DCMAKE_MAKE_PROGRAM=ninja -GNinja
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.30/Modules/CMakeDetermineSystem.cmake:152 (message):
  Could not find toolchain file:
  "C:\Users\ay0ks\Workspace\Red\Auxillary\Toolchains\Windows-x64.cmake"
Call Stack (most recent call first):
  CMakeLists.txt:9 (project)

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
PS C:\Users\ay0ks\Workspace\Red\Auxillary\Scripts>

```

However, same as on Linux, if I run the command myself, everything works like it should:

```auto
PS C:\Users\ay0ks\Workspace\Red\Auxillary\Scripts> cmake -S C:\Users\ay0ks\Workspace\Red -B C:\Users\ay0ks\Workspace\Red\Destination\Build\Windows-x64-Windows-x64\MSVC-19.43.34808.0-MSVC-14.43.34808.0\Debug -DCMAKE_TOOLCHAIN_FILE="C:\Users\ay0ks\Workspace\Red\Auxillary\Toolchains\Windows-x64.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_FLAGS="-fdiagnostics-color=always" -DCMAKE_MAKE_PROGRAM=ninja -GNinja
-- The C compiler identification is MSVC 19.43.34808.0
-- The CXX compiler identification is MSVC 19.43.34808.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (5.8s)
-- Generating done (0.3s)
-- Build files have been written to: C:/Users/ay0ks/Workspace/Red/Destination/Build/Windows-x64-Windows-x64/MSVC-19.43.34808.0-MSVC-14.43.34808.0/Debug
PS C:\Users\ay0ks\Workspace\Red\Auxillary\Scripts>

```

I’ve mirrored this problem to Python’s forum in case this isn’t exactly CMake’s problem: [CMake executed by a Python script can't find the file which exists - Python Help - Discussions on Python.org](https://discuss.python.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/85648)  
Thanks in advance.

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [March 23, 2025, 10:13pm UTC](https://discourse.cmake.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/13798/2 "2025-03-23T22:13:14Z")

</div>

I don’t think this has anything to do with CMake.

Try to use `shell=True`, single string arguments are platform dependent. Please see the Python documentation of `args` for details.  
The better way may be to avoid quoting yourself with `"` and instead use a sequence of arguments.

---

<div class="post-metadata">

### Author: ![ay0ks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ay0ks/32/5430_2.png) [@ay0ks](https://discourse.cmake.org/u/ay0ks)
#### Post date: [March 24, 2025, 7:07am UTC](https://discourse.cmake.org/t/cmake-executed-by-a-python-script-cant-find-the-file-which-exists/13798/3 "2025-03-24T07:07:29Z")

</div>

The `shell` keyword argument completely fell out of my mind, it works now! Thanks!
