我在python中导入theano时遇到问题。当我在Windows 7 64位的python 27 32位中导入Theano时,出现以下错误和警告:
我还应该补充一点,目前我已经安装了GCC 4.8.1。
我必须做些什么才能修复它。
谢谢,
阿夫申
WARNING (theano.gof.cmodule): OPTIMIZATION WARNING: Theano was not able to find the g++ parameters that tune the compilation to your specific CPU. This can slow down the execution of Theano functions. Please submit the following lines to Theano's mailing list so that we can fix this problem:
['# 1 ""\n', 'Reading specs from \\cygnus\\cygwin-b20\\H-i586-cygwin32\\lib\\gcc-lib\\i586-cygwin32\\egcs-2.91.57\\specs\n', 'gcc version egcs-2.91.57 19980901 (egcs-1.1 release)\n', ' \\cygnus\\cygwin-b20\\H-i586-cygwin32\\lib\\gcc-lib\\i586-cygwin32\\egcs-2.91.57\\cpp.exe -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__i386__ -D_WIN32 -D__WINNT__ -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__i386 -D__WINNT -Asystem(winnt) -Acpu(i386) -Amachine(i386) -remap -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium -D__pentium__ -D__CYGWIN32__ -D__CYGWIN__ -\n', 'GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (80386, BSD syntax)\n', '#include "..." search starts here:\n', '#include <...> search starts here:\n', ' \\cygnus\\cygwin-b20\\H-i586-cygwin32\\lib\\gcc-lib\\i586-cygwin32\\egcs-2.91.57\\..\\..\\..\\..\\..\\include\n', ' \\cygnus\\cygwin-b20\\H-i586-cygwin32\\lib\\gcc-lib\\i586-cygwin32\\egcs-2.91.57\\..\\..\\..\\..\\i586-cygwin32\\include\n', ' \\cygnus\\cygwin-b20\\H-i586-cygwin32\\lib\\gcc-lib\\i586-cygwin32\\egcs-2.91.57\\include\n', 'End of search list.\n']
===============================
00001 #include <Python.h>
00002 #include "structmember.h"
00003 #include <sys/time.h>
00004
00005 // Old Python compatibility from here:
00006 // http://www.python.org/dev/peps/pep-0353/
00007 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
00008 typedef int Py_ssize_t;
00009 #define PY_SSIZE_T_MAX INT_MAX
00010 #define PY_SSIZE_T_MIN INT_MIN
00011 // This one was taken from:
00012 // http://svn.python.org/projects/python/trunk/Modules/_ctypes/ctypes.h
00013 #define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob)
00014 #endif
00015
00016 #if PY_VERSION_HEX >= 0x03000000
00017 #include "numpy/npy_3kcompat.h"
00018 #define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
00019 #define PyCObject_GetDesc NpyCapsule_GetDesc
00020 #define PyCObject_Check NpyCapsule_Check
00021 #endif
00022
00023 #ifndef Py_TYPE
00024 #define Py_TYPE(obj) obj->ob_type
00025 #endif
00026
00027 /**
00028
00029 TODO:
00030 - Check max supported depth of recursion
00031 - CLazyLinker should add context information to errors caught during evaluation. Say what node we were on, add the traceback attached to the node.
00032 - Clear containers of fully-useed intermediate results if allow_gc is 1
00033 - Add timers for profiling
00034 - Add support for profiling space used.
00035
00036
00037 */
00038 static double pytime(const struct timeval * tv)
00039 {
00040 struct timeval t;
00041 if (!tv)
00042 {
00043 tv = &t;
00044 gettimeofday(&t, NULL);
00045 }
00046 return (double) tv->tv_sec + (double) tv->tv_usec / 1000000.0;
00047 }
00048
00049 /**
00050 Helper routine to convert a PyList of integers to a c array of integers.
00051 */
00052 static int unpack_list_of_ssize_t(PyObject * pylist, Py_ssize_t **dst, Py_ssize_t *len,
00053 const char* kwname)
00054 {
00055 Py_ssize_t buflen, *buf;
00056 if (!PyList_Check(pylist))
00057 {
00058 PyErr_Format(PyExc_TypeError, "%s must be list", kwname);
00059 return -1;
00060 }
00061 assert (NULL == *dst);
00062 *len = buflen = PyList_Size(pylist);
00063 *dst = buf = (Py_ssize_t*)calloc(buflen, sizeof(Py_ssize_t));
00064 assert(buf);
00065 for (int ii = 0; ii < buflen; ++ii)
00066 {
00067 PyObject * el_i = PyList_GetItem(pylist, ii);
00068 Py_ssize_t n_i = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
00069 if (PyErr_Occurred())
00070 {
00071 free(buf);
00072 *dst = NULL;
00073 return -1;
00074 }
00075 buf[ii] = n_i;
00076 }
00077 return 0;
00078 }
00079
00080 /**
00081
00082 CLazyLinker
00083
00084
00085 */
00086 typedef struct {
00087 PyObject_HEAD
00088 /* Type-specific fields go here. */
00089 PyObject * nodes; // the python list of nodes
00090 PyObject * thunks; // python list of thunks
00091 PyObject * pre_call_clear; //list of cells to clear on call.
00092 int allow_gc;
00093 Py_ssize_t n_applies;
00094 int n_vars; // number of variables in the graph
00095 int * var_computed; // 1 or 0 for every variable
00096 PyObject ** var_computed_cells;
00097 PyObject ** var_value_cells;
00098 Py_ssize_t **dependencies; // list of vars dependencies for GC
00099 Py_ssize_t *n_dependencies;
00100
00101 Py_ssize_t n_output_vars;
00102 Py_ssize_t * output_vars; // variables that *must* be evaluated by call
00103
00104 int * is_lazy; // 1 or 0 for every thunk
00105
00106 Py_ssize_t * var_owner; // nodes[[var_owner[var_idx]]] is var[var_idx]->owner
00107 int * var_has_owner; // 1 or 0
00108
00109 Py_ssize_t * node_n_inputs;
00110 Py_ssize_t * node_n_outputs;
00111 Py_ssize_t ** node_inputs;
00112 Py_ssize_t ** node_outputs;
00113 Py_ssize_t * node_inputs_outputs_base; // node_inputs and node_outputs point into this
00114 Py_ssize_t * node_n_prereqs;
00115 Py_ssize_t ** node_prereqs;
00116
00117 Py_ssize_t * update_storage; // input cells to update with the last outputs in output_vars
00118 Py_ssize_t n_updates;
00119
00120 void ** thunk_cptr_fn;
00121 void ** thunk_cptr_data;
00122 PyObject * call_times;
00123 PyObject * call_counts;
00124 int do_timing;
00125 int need_update_inputs;
00126 int position_of_error; // -1 for no error, otw the index into `thunks` that failed.
00127 } CLazyLinker;
00128
00129
00130 static void
00131 CLazyLinker_dealloc(PyObject* _self)
00132 {
00133 CLazyLinker* self = (CLazyLinker *) _self;
00134 free(self->thunk_cptr_fn);
00135 free(self->thunk_cptr_data);
00136
00137 free(self->is_lazy);
00138
00139 free(self->update_storage);
00140
00141 if (self->node_n_prereqs)
00142 {
00143 for (int i = 0; i < self->n_applies; ++i)
00144 {
00145 free(self->node_prereqs[i]);
00146 }
00147 }
00148 free(self->node_n_prereqs);
00149 free(self->node_prereqs);
00150 free(self->node_inputs_outputs_base);
00151 free(self->node_n_inputs);
00152 free(self->node_n_outputs);
00153 free(self->node_inputs);
00154 free(self->node_outputs);
00155
00156 if (self->dependencies)
00157 {
00158 for (int i = 0; i < self->n_vars; ++i)
00159 {
00160 free(self->dependencies[i]);
00161 }
00162 free(self->dependencies);
00163 free(self->n_dependencies);
00164 }
00165
00166 free(self->var_owner);
00167 free(self->var_has_owner);
00168 free(self->var_computed);
00169 if (self->var_computed_cells)
00170 {
00171 for (int i = 0; i < self->n_vars; ++i)
00172 {
00173 Py_DECREF(self->var_computed_cells[i]);
00174 Py_DECREF(self->var_value_cells[i]);
00175 }
00176 }
00177 free(self->var_computed_cells);
......
(I just removed some codes, because Stachoverflow does not allow more than 30000 character......
......
01052 #endif
01053 #if defined(NPY_PY3K)
01054 #define RETVAL m
01055 PyMODINIT_FUNC
01056 PyInit_lazylinker_ext(void) {
01057 #else
01058 #define RETVAL
01059 PyMODINIT_FUNC
01060 initlazylinker_ext(void)
01061 {
01062 #endif
01063 PyObject* m;
01064
01065 lazylinker_ext_CLazyLinkerType.tp_new = PyType_GenericNew;
01066 if (PyType_Ready(&lazylinker_ext_CLazyLinkerType) < 0)
01067 return RETVAL;
01068 #if defined(NPY_PY3K)
01069 m = PyModule_Create(&moduledef);
01070 #else
01071 m = Py_InitModule3("lazylinker_ext", lazylinker_ext_methods,
01072 "Example module that creates an extension type.");
01073 #endif
01074 Py_INCREF(&lazylinker_ext_CLazyLinkerType);
01075 PyModule_AddObject(m, "CLazyLinker", (PyObject *)&lazylinker_ext_CLazyLinkerType);
01076
01077 return RETVAL;
01078 }
01079
01080
Problem occurred during compilation with the command line below:
C:\cygnus\cygwin-b20\H-i586-cygwin32\bin\g++.exe -shared -g -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m32 -IC:\python2732\lib\site-packages\numpy-1.9.0-py2.7-win32.egg\numpy\core\include -IC:\python2732\include -o C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\lazylinker_ext.pyd C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\mod.cpp -LC:\python2732\libs -LC:\python2732 -lpython27
===============================
g++.exe: unrecognized option `-shared'
C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\mod.cpp:0: malformed option `-D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'
In file included from C:\python2732\include\Python.h:8,
from C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\mod.cpp:1:
C:\python2732\include\pyconfig.h:269: warning: #warning "Please use an up-to-date version of gcc! (>2.91 recommended)"
Traceback (most recent call last):
File "C:\Users\Dell\Documents\Pyton\Home Work 1\test-theano\test-theano.py", line 6, in <module>
from theano import *
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\__init__.py", line 55, in <module>
from theano.compile import \
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\compile\__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\compile\function_module.py", line 18, in <module>
import theano.compile.mode
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\compile\mode.py", line 11, in <module>
import theano.gof.vm
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\gof\vm.py", line 568, in <module>
import lazylinker_c
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\gof\lazylinker_c.py", line 116, in <module>
preargs=args)
File "C:\python2732\lib\site-packages\theano-0.7.0-py2.7.egg\theano\gof\cmodule.py", line 2010, in compile_str
(status, compile_stderr.replace('\n', '. ')))
Exception: Compilation failed (return status=1): g++.exe: unrecognized option `-shared'. C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\mod.cpp:0: malformed option `-D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'. In file included from C:\python2732\include\Python.h:8,. from C:\Users\Dell\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_30_Stepping_5_GenuineIntel-2.7.8-32\lazylinker_ext\mod.cpp:1:. C:\python2732\include\pyconfig.h:269: warning: #warning "Please use an up-to-date version of gcc! (>2.91 recommended)".
最佳答案
您应该检查Windows路径,并确保它们没问题。
关于python - Theano导入错误-windows 7,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32018923/