未定义的符号:PyExc_RecurationError

undefined symbol: PyExc_RecursionError

本文关键字:RecurationError PyExc 符号 未定义      更新时间:2023-10-16
Traceback (most recent call last):                                                                                                                    
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 17, in <module>                                                          
from . import multiarray                                                                                                                          
File "/usr/local/lib/python3.5/dist-packages/numpy/core/multiarray.py", line 14, in <module>                                                        
from . import overrides                                                                                                                           
File "/usr/local/lib/python3.5/dist-packages/numpy/core/overrides.py", line 7, in <module>                                                          
from numpy.core._multiarray_umath import (                                                                                                        
ImportError: /usr/local/lib/python3.5/dist-packages/numpy/core/_multiarray_umath.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyExc_RecursionError                                                                                                                                                    
During handling of the above exception, another exception occurred:                                                                                   
Traceback (most recent call last):                                                                                                                    
File "<string>", line 1, in <module>                                                                                                                
File "/usr/local/lib/python3.5/dist-packages/numpy/__init__.py", line 142, in <module>                                                              
from . import core
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 47, in <module>
raise ImportError(msg)
ImportError: 
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.5 from "/usr/bin/python3",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.4" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues.  Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: /usr/local/lib/python3.5/dist-packages/numpy/core/_multiarray_umath.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyExc_RecursionError

在使用cpython api通过C++运行Python代码时出现此错误。python文件只是导入numpy。有人知道可能的问题和解决方案是什么吗?

我尝试了从源代码编译多个不同的python安装,但似乎没有效果。目前,我在系统上只安装了python3.5和python3.5m。这些是系统附带的默认python安装(ubuntu 16.04(

以下是cmake文件:

cmake_minimum_required(VERSION 2.8)
project(testproject C CXX)

set (CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_JS_INC "$ENV{HOME}/.cmake-js/node-x64/v10.15.3/include/node;/home/project/code/node_modules/nan")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Release)
#------ PACKAGES ------
find_package(OpenCV 3 REQUIRED)
#---------------------------

#------ CORE ----
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h" "nan/*.cpp" "nan/*.h"
"drivers/*.cpp" "drivers/*.h"
"drivers/webstream/*.cpp" "drivers/webstream/*.h"
)
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC}
PUBLIC "."
)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
#---------------------------

#------ EVAL PACKAGES ------
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
#---------------------------
# c-python config
include_directories(${PROJECT_NAME} SYSTEM PUBLIC "/usr/include/python3.5/")
include_directories(${PROJECT_NAME} SYSTEM PUBLIC "/usr/lib/python3.5/")
include_directories(${PROJECT_NAME} SYSTEM PUBLIC "/usr/local/lib/python3.5/")
include_directories(${PROJECT_NAME} SYSTEM PUBLIC "/usr/local/lib/python3.5/dist-packages/numpy/core/include/")
add_library(python_c SHARED IMPORTED)
set_target_properties(python_c PROPERTIES IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libpython3.5m.so")
target_link_libraries(
${PROJECT_NAME}
PUBLIC python_c
)

#add_executable
add_executable(code pawan.cpp)
target_link_libraries(code
PUBLIC python_c
PUBLIC ${OpenCV_LIBS})

cmake的命令是:

cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3.5 ..

通过cmake,我还创建了一个可执行文件"code"。可执行文件运行良好。当使用通过cmake创建的代码直通库时,会出现错误。

这是pawan.cpp 文件

#include "python3.5/Python.h"
#include <iostream>
#include <string>
using namespace std;
void fun() {
cout << "using cpython......................................................................00" << endl;
Py_Initialize();
PyRun_SimpleString ("print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^11')");
//    if(PyArray_API == NULL){
//        _import_array();
//    }
PyRun_SimpleString ("import numpy; print(numpy.__file__)");
PyRun_SimpleString ("print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^22')");
}

感谢您提供完整的cmake文件。在那里,您构建的应用程序包括Python3.5并与之链接。然而,numpy的错误来自_multiarray_umath.cpython-38-x86_64-linux-gnu.so,因此是为Python3.8构建的,可能是在b/c中发现的,它是当前环境中Python的版本。为不同版本的CPython构建的C扩展通常是不兼容的。

除非您对Python3.5有特定的需求,否则在这种情况下,我建议确保它在您的环境中正确设置(即,通过将PATHLD_LIBRARY_PATH指向Python350版本(,并首先安装numpy。但如果3.8能做到,你可以简单地让cmake从环境中获取它。类似这样的东西:

find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;sys.stdout.write(sys.version[:3])"
OUTPUT_VARIABLE PYTHON_VERSION)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;sys.stdout.write(sys.prefix)"
OUTPUT_VARIABLE PYTHON_PREFIX)
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PYTHON_PREFIX})
endif()
set(Python_ADDITIONAL_VERSIONS ${PYTHON_VERSION})
find_package(PythonLibs REQUIRED)
if (NOT PYTHONLIBS_FOUND)
message(FATAL_ERROR "PythonLibs package not found and python component required")
endif()

并将"${PYTHON_INCLUDE_PATH}"添加到您的项目includes中,并将"{$PythonLibs}"添加到链接您的目标。

相关文章:
  • 没有找到相关文章