最近我必须更改或更新了软件包,因为现在启动Python脚本(嵌入C ++)时出现此错误:
ERROR 1: NUMPY driver was compiled against GDAL 2.2 but current library version is 1.11
以下是我在Python代码中调用的软件包:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import gdal as gd
import math
import numpy as np
import scipy.ndimage
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource, Normalize
import Image
from scipy.ndimage.filters import gaussian_filter
import sys
当我输入时:gdalinfo --version 我得到:GDAL 2.2.2,发布于2017/09/15
我想我的计算机上现在有其他版本的Python和GDAL,但找不到解决该错误的方法。
我可以使用python2.7毫无问题地运行python代码,似乎只有从C ++代码中调用该代码时,我才会收到此错误。
我使用此函数将python代码加载到C ++程序中:
PithonExtension::PithonExtension(char* pithon_path, char* pithon_filename,
char* program_name, const std::string& repository) {
Py_SetProgramName(program_name);
// Initialize the Python Interpreter
Py_Initialize();
// Log
PyObject *sys = PyImport_ImportModule("sys");
PyObject* io_stdout = PyFile_FromFile(stdout, "stdout", "a", nullptr);
PyObject_SetAttrString(sys, "stdout", io_stdout);
PyObject* io_stderr = PyFile_FromFile(stderr, "stderr", "a", nullptr);
PyObject_SetAttrString(sys, "stderr", io_stderr);
PyObject* io_stdin = PyFile_FromFile(stdin, "stdin", "r", nullptr);
PyObject_SetAttrString(sys, "stdin", io_stdin);
// Tell the program where to find the python file we will launch.
PyObject *sysPath = PySys_GetObject("path");
PyObject *path = PyString_FromString(pithon_path);
int result = PyList_Insert(sysPath, 0, path);
// First, import module.
PyObject* myModuleString = PyString_FromString(pithon_filename);
PyObject* myModule = PyImport_Import(myModuleString);
// Then getting a reference to your function.
PyObject* myFunction = PyObject_GetAttrString(myModule,(char*)"workflow");
PyObject* args = PyTuple_Pack(1,PyString_FromString(repository.c_str()));
// Then getting your result.
PyObject* myResult = PyObject_CallObject(myFunction, args);
}
GDB告诉我:程序收到信号SIGSEGV,分段错误。 来自/usr/lib/libgdal.so.20中的GDALRasterBand :: ReportError(CPLErr,int,char const *,...)()中的0x00007fffe0fcb390