pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

Python Path Configuration & Abort() Error

Open NulledBird opened this issue 7 months ago • 0 comments

Required prerequisites

  • [x] Make sure you've read the documentation. Your issue may be addressed there.
  • [x] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [x] Consider asking first in the Gitter chat room or in a Discussion.

What version (or hash if on master) of pybind11 are you using?

2.13.6

Problem description

I have a setup where I am trying to compile a version of CPython (with a custom CMake) and use it in pybind11's embed mode.

Upon compiling, I get no errors, however running the compiled executable returns

Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'D:\\lime\\bin\\Debug\\lime.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'D:\\lime\\bin\\Debug\\lime.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'D:\\lime\\bin\\Debug\\lime.zip',
    '',
    '.\\Lib',
    '.\\Lib\\lib-dynload',
    '.\\Lib\\lib-dynload\\Debug',
    '.\\Lib\\plat-win32',
    '.\\Lib\\lib-tk',
    'D:\\lime\\bin\\Debug',
  ]

And a popup window that says

Debug Error Program: abort() has been called (Press Retry to debug the application)

The main.cpp file is copied directly from the tutorial.

Reproducible example code

cmake_minimum_required(VERSION 3.5...3.29)
project(test LANGUAGES CXX)

if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
    set(CMAKE_BUILD_TYPE "Debug")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

set(PYTHON_VERSION "3.9.22" CACHE STRING "The version of Python to build." FORCE)
add_subdirectory(ext/python)
get_directory_property(PYTHONPATH DIRECTORY ext/python DEFINITION PYTHONHOME)
get_directory_property(BIN_INSTALL_DIR DIRECTORY ext/python DEFINITION BIN_INSTALL_DIR)
set(ENV{PYTHONPATH} "${CMAKE_CURRENT_BINARY_DIR}/ext/python/${PYTHONPATH}")
set(ENV{PYTHONHOME} "${CMAKE_CURRENT_BINARY_DIR}/ext/python/${BIN_INSTALL_DIR}/${CMAKE_BUILD_TYPE}/")

include_directories("${CMAKE_CURRENT_BINARY_DIR}/ext/python/include" "$ENV{PYTHONHOME}/PC/")
set(PYBIND11_NOPYTHON TRUE)
set(Python_EXECUTABLE "$ENV{PYTHONHOME}/python.exe")
set(ENV{PATH} "$ENV{PYTHONHOME}:$ENV{PATH}")
add_subdirectory(ext/pybind11)


file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS include/*.hpp)

add_executable(test src/main.cpp)
target_sources(test PRIVATE ${SOURCES} ${HEADERS})
include_directories(include)

target_link_libraries(test PRIVATE pybind11::embed libpython-static)

Is this a regression? Put the last known working version here if it is.

Not a regression

NulledBird avatar May 07 '25 02:05 NulledBird