I'm trying to build c++ engine interfaces for python, using boost/python. Python fails when in an anaconda environment. I've stripped the c++ down to the following (simplepython.cpp), which still fails:
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
namespace R3 {
class Coordinate {
public:
Coordinate() : x(0), y(0), z(0) {}
Coordinate(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
double getX() const { return x;}
double getY() const { return y;}
double getZ() const { return z;}
private:
double x, y, z;
};
}
BOOST_PYTHON_MODULE(simplepython) {
// An established convention for using boost.python.
using namespace boost::python;
Py_Initialize();
class_<R3::Coordinate>("R3Coordinate", init<>())
.def(init<int, int, int>())
.def("getX", &R3::Coordinate::getX)
.def("getY", &R3::Coordinate::getY)
.def("getZ", &R3::Coordinate::getZ)
;
}
trying it:
$> python -c ‘import sys; print(sys.executable); import simplepython
... SystemError: initialization of _heapq did not return an extension module
Sys/build details:
Mac OS Mojave, 10.14.6 Python version 3.7.4, Conda 4.8.3 C++ et al: Apple clang version 11.0.0 (clang-1100.0.33.17)
conda install was: conda install -c anaconda boost
Boost version: boost-1.67.0
Build:
g++ -I/opt/anaconda3/include/python3.7m -I/opt/anaconda3/include/python3.7m -I/opt/anaconda3/include -O2 -fPIC -std=c++11 -Iinclude -c -o objs/simplepython.o src/simplepython.cpp
g++ -Wl,-rpath,/opt/anaconda3/lib -shared -o lib/simplepython.so objs/simplepython.o -L/opt/anaconda3/lib -Llib -lpython3.7m -ldl -framework CoreFoundation -lboost_python37 -lboost_numpy37
Full results:
/opt/anaconda3/bin/python
Error processing line 1 of /opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.1.1-py3.7-nspkg.pth:
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/opt/anaconda3/lib/python3.7/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/opt/anaconda3/lib/python3.7/contextlib.py", line 5, in <module>
from collections import deque
File "/opt/anaconda3/lib/python3.7/collections/__init__.py", line 24, in <module>
import heapq as _heapq
File "/opt/anaconda3/lib/python3.7/heapq.py", line 587, in <module>
from _heapq import *
SystemError: initialization of _heapq did not return an extension module
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site.py", line 579, in <module>
main()
File "/opt/anaconda3/lib/python3.7/site.py", line 566, in main
known_paths = addsitepackages(known_paths)
File "/opt/anaconda3/lib/python3.7/site.py", line 349, in addsitepackages
addsitedir(sitedir, known_paths)
File "/opt/anaconda3/lib/python3.7/site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "/opt/anaconda3/lib/python3.7/site.py", line 178, in addpackage
import traceback
File "/opt/anaconda3/lib/python3.7/traceback.py", line 3, in <module>
import collections
File "/opt/anaconda3/lib/python3.7/collections/__init__.py", line 24, in <module>
import heapq as _heapq
File "/opt/anaconda3/lib/python3.7/heapq.py", line 587, in <module>
from _heapq import *
SystemError: initialization of _heapq did not return an extension module
Thanks for any help!
Aucun commentaire:
Enregistrer un commentaire