pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[QUESTION] Cannot import 'sysconfig' during cmake configuration

Open hyt589 opened this issue 4 years ago • 4 comments

Hi, my project builds fine in dev environment, but when I throw it into a drone CI docker image it gives me the following error:

-- pybind11 v2.6.2 dev1
-- Found PythonInterp: /usr/bin/python3.6 (found version "3.6.9") 
CMake Error at python/pybind/tools/FindPythonLibsNew.cmake:131 (message):
  Python config failure:

  Traceback (most recent call last):

    File "<string>", line 1, in <module>

  ImportError: cannot import name 'sysconfig'

Call Stack (most recent call first):
  python/pybind/tools/pybind11Tools.cmake:38 (find_package)
  python/pybind/tools/pybind11Common.cmake:201 (include)
  python/pybind/CMakeLists.txt:169 (include)

I tried building directly in the docker image and it also builds fine. I also tried importing the sysconfig package in the python REPL and it also works fine. Any idea what's causing this?

hyt589 avatar Dec 28 '20 02:12 hyt589

@hyt589 Can you reproduce this in a docker image that's available for us to try?

YannickJadoul avatar Dec 28 '20 11:12 YannickJadoul

Pybind's cmake is doing from distutils import sysconfig as s, not import sysconfig as s.

bstaletic avatar Dec 28 '20 12:12 bstaletic

Installing python3-distutils solved it for me.

miquelmassot avatar Dec 14 '22 06:12 miquelmassot

I installed python3-distutils, the error persisted. The clue lies in the error itself actually. The error is

-- Found PythonInterp: /usr/bin/python3.7 (found version "3.7.5") 
CMake Error at /usr/lib/cmake/pybind11/FindPythonLibsNew.cmake:96 (message):
  Python config failure:

  Traceback (most recent call last):

    File "<string>", line 1, in <module>

  ImportError: cannot import name 'sysconfig' from 'distutils'
  (/usr/lib/python3.7/distutils/__init__.py)

When I run python3 in a terminal, it gives me a version 3.8. So with synaptic package manager, I uninstalled all packages related to python 3.7. Then the error vanished.

JzHuai0108 avatar Dec 04 '24 02:12 JzHuai0108