Ultimaker / cura-build-environment

CMake project to build dependencies for Cura
GNU Affero General Public License v3.0
24 stars 55 forks source link

Import error in python 3.8: No module named '_abc' #102

Open MohamadHalwani opened 3 years ago

MohamadHalwani commented 3 years ago

I have an issue trying to build cura-build-environment, after running sudo make in build file I'm getting this..

 [ 43%] Performing configure step for 'Savitar'
-- Find shared libpython: /usr/local/lib/libpython3.8.so
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/abc.py", line 64, in <module>
ImportError: No module named '_abc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/io.py", line 52, in <module>
  File "/usr/local/lib/python3.8/abc.py", line 68, in <module>
  File "/usr/local/lib/python3.8/_py_abc.py", line 35
    def __new__(mcls, name, bases, namespace, /, **kwargs):
                                              ^
SyntaxError: invalid syntax
CMake Error at cmake/FindSIP.cmake:47 (message):
  Failed to get Python3_SITELIB.  Error:
Call Stack (most recent call first):
  CMakeLists.txt:48 (find_package)

-- Configuring incomplete, errors occurred!

I tried re-installing python3.8 but still no luck. This is a snippet of the CMakeLists.txt of Savitar, which I think is causing the issue:

project(savitar)
cmake_minimum_required(VERSION 3.8)    
##### find python
execute_process(COMMAND python3-config --prefix OUTPUT_VARIABLE PYTHON_SEARCH_PATH)
string(REGEX REPLACE "\n$" "" PYTHON_SEARCH_PATH "${PYTHON_SEARCH_PATH}")
file(GLOB_RECURSE PYTHON_DY_LIBS ${PYTHON_SEARCH_PATH}/lib/libpython*.dylib ${PYTHON_SEARCH_PATH}/lib/libpython*.so)
if (PYTHON_DY_LIBS)
    list(GET PYTHON_DY_LIBS 0 PYTHON_LIBRARY)
    message("-- Find shared libpython: ${PYTHON_LIBRARY}")
else()
    message(WARNING "Cannot find shared libpython, try find_package")
endif()#####

if(BUILD_PYTHON)
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

    # FIXME: Remove the code for CMake <3.12 once we have switched over completely.
    # FindPython3 is a new module since CMake 3.12. It deprecates FindPythonInterp and FindPythonLibs.
    if(${CMAKE_VERSION} VERSION_LESS 3.12)
        # FIXME: Use FindPython3 to find Python, new in CMake 3.12.
        # However currently on our CI server it finds the wrong Python version and then doesn't find the headers.
        find_package(PythonInterp 3.4 REQUIRED)
        find_package(PythonLibs 3.4 REQUIRED)
    find_package(Python3_EXECUTABLE Interpreter)
    else()
        # Use FindPython3 for CMake >=3.12
        find_package(Python3 3.4 REQUIRED COMPONENTS Interpreter Development)

    endif()

    find_package(SIP REQUIRED)
    if(NOT DEFINED LIB_SUFFIX)
        set(LIB_SUFFIX "")
    endif()

    include_directories(python/ src/ ${SIP_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS})
endif()

The first part of the CMakelists file starts by #### is added by me since I was facing another issue ! Which is this one:

  File "/usr/local/lib/python3.8/abc.py", line 64, in <module>
ImportError: No module named '_abc'

please help :)

alexwoo1900 commented 3 years ago

There is no enough information to determine the cause of error, but I think the point is Python.

cura-build-environment downloads its own Python program and installs plugins for it. Then use it to install other modules. If you installed another Python in OS before, cura-build-environment may confuse them.

MohamadHalwani commented 3 years ago

I just commented the find_package(SIP REQUIRED) for now, it worked.

Ghostkeeper commented 3 years ago

The _abc module is built-in in Python itself. This is what I get when importing it in a Python terminal:

>>> import _abc
>>> _abc
<module '_abc' (built-in)>

If you don't have the _abc module in your Python installation, I think your Python installation is broken. Since you're apparently not using the Python installation created in cura-build-environment but the one on your system, maybe you might want to repair the Python installation on your system somehow. There is very little we can do about it.