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
Getting this error on running Python code through C++ using cpython api. The python file simply imports numpy. Does anyone knows what could be the possible issue and its solution?
I tried multiple different python installations by compiling them from source, but that seems to have no effect. Currently I have only python3.5 and python3.5m installed on the system. These are the default python installations that came with the system (ubuntu 16.04).
Below is the cmake file:
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})
Command for cmake is:
cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3.5 ..
Through cmake, I also created an executable file "code". The executable is working fine. The error comes when using the code through library created through cmake.
This is the file 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')");
}