I do not understand how to install python through vcpkg. The CMakesLists file I have is:
cmake_minimum_required(VERSION 3.8)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "./vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
project(test)
find_package(Python3 COMPONENTS Development REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test PRIVATE Python3::Python)
The c++ file was taken directly from https://docs.python.org/3/extending/embedding.html#very-high-level-embedding
everything compiles and links without error but when executing it gives this error:
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'C:\Users\smith\OneDrive\Desktop\OSU\vcpkg-python-test\build\Debug\test.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\smith\\OneDrive\\Desktop\\OSU\\vcpkg-python-test\\build\\Debug\\test.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\smith\\OneDrive\\Desktop\\OSU\\vcpkg-python-test\\build\\Debug\\test.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\\Users\\smith\\OneDrive\\Desktop\\OSU\\vcpkg-python-test\\build\\Debug\\python310_d.zip',
'.\\DLLs',
'.\\lib',
'C:\\Users\\smith\\OneDrive\\Desktop\\OSU\\vcpkg-python-test\\build\\Debug',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000062bc (most recent call first):
<no Python frame>
I don't understand what I am doing wrong or if there was some step I missed.
The full example code can be found at https://github.com/Drew-j-Smith/vcpkg-python-test
This was run on windows 10
edit:
Adding this to the CMakeLists.txt (after finding python):
get_filename_component(Python3_EXECUTABLE_DIR ${Python3_EXECUTABLE} DIRECTORY)
add_definitions(-DPYTHON_LIB=L"${Python3_EXECUTABLE_DIR}/Lib")
And calling
Py_SetPath(PYTHON_LIB);
before python is initialized does fix the issue. However, this seems like a hack to me. I am still looking for a robust solution.