pybind / pybind/pybind11

Python Path Configuration & Abort() Error

Open
#5,644 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied CMake configuration, the pybind11 embed tutorial, and src/main.cpp, then run the reproducible example to inspect the reported Python path configuration and abort dialog. Compare the custom CPython build layout under ext/python with the PYTHONHOME, PYTHONPATH, executable, and linked libpython settings. Done means the cause and a reproducible configuration change are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.