Python theano未定义符号:_ZdlPvm错误

时间:2017-03-11 00:36:50

标签: python theano keras archlinux

我正在尝试执行此代码:

import matplotlib.pyplot as plt
import numpy as np
from keras.models import Sequential
from keras.layers import Dense

x = np.linspace(-3, 3, 1000).reshape(-1, 1)

def f(x):    
    return 2 * x + 5

f = np.vectorize(f)
y = f(x)    

def baseline_model():
    model = Sequential()
    model.add(Dense(1, input_dim=1, activation='linear'))
    model.compile(loss='mean_squared_error', optimizer='sgd')
    return model

model = baseline_model()
model.fit(x, y, nb_epoch=100, verbose = 0)

但是在最后一行它会引发这个错误:ImportError: /home/puck/.theano/compiledir_Linux-4.4--MANJARO-x86_64-with-glibc2.2.5--3.6.0-64/tmpgk36rmkt/mf0c860ada3decf909d2c7248bdfcff39.so: undefined symbol: _ZdlPvm

Here是完整的追溯。 这是我第一次使用keras和theano,所以我不知道该怎么做。

有关软件版本的一些信息:

Linux 4.4.52-1-MANJARO
GCC 6.3.1
Anaconda 4.3.0
Python 3.6.0 
IPython 5.1.0
Theano 0.8.2
Keras 1.2.2

2 个答案:

答案 0 :(得分:2)

要解决问题,我安装了gcc 4.9.3并在~/.theanorc这些行添加:

[global]
cxx = /usr/bin/g++-4.9.3

答案 1 :(得分:1)

由于您已在机器中安装了预先构建的theano软件包,因此需要某些gcc和相关的lib才能在计算机中进行调用。 github链接中提供的解决方案对您仍然有效,但是因为您没有构建代码,该解决方案将无法为您工作,因为theano仍在访问预先安装的库。

以下是您可以尝试的内容:

  • 你必须拥有与theano不兼容的gcc和g ++更高版本,所以通过使用OS命令卸载它们来删除gcc和g ++
  • 删除theano包
  • 将gcc和g ++安装到4.9版本,因为这是最多的命令版本
  • 重新安装theano> $ pip3安装theano --user

我相信这可以帮助你让你的theano工作。