g++.exe: error: and: No such file or directory
g++.exe: error: Settings\Administrator.theano\compiledir_Windows-XP-5.1.2600-SP3-x86_Family_6_Model_15_Stepping_13_GenuineIntel-2.7.12-32\lazylinker_ext\lazylinker_ext.pyd: No such file or directory
g++.exe: error: C:\Documents: No such file or directory
g++.exe: error: and: No such file or directory
g++.exe: error: Settings\Administrator.theano\compiledir_Windows-XP-5.1.2600-SP3-x86_Family_6_Model_15_Stepping_13_GenuineIntel-2.7.12-32\lazylinker_ext\mod.cpp: No such file or directory
这个错误我参考了 StackOverflow, https://stackoverflow.com/questions/33702668/using-theano-on-windows-missing-lazylinker-ext-pyd
发现可能是 https://stackoverflow.com/questions/3848357/createprocess-no-such-file-or-directory
就是CreateProcess的问题, 也就是调用系统命令出错, print_command_line_error()
一般是路径出错, 因为subprocess经常出错.
问题出了, 查找 lazylinker_ext.pyd, 发现系统中确实没有这个文件, 那么这个文件在哪里? 实际上theano在第一次import theano的时候, 调用g++自动编译出来的, 在编译的时候出错了, 也就看不到这个文件了.
那么为什么出错, 错在哪里? 问题就是 命令行错了, 有几个路径带空格, windows就说不存在, 比如C:\Document and Settings, 中间带个空格, 就不行了.
解决的办法就是 两头都加上双引号, 单引号我没有试.
“C:\Document and Settings…..” 这样
仔细观察错误的命令行:
Problem occurred during compilation with the command line below: "C:\MinGW\bin\g++.exe" -shared -g -march=core2 -mcx16 -msahf -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt --param l1-cache-size=0 --param l1-cache-line-size=0 --param l2-cache-size=1024 -mtune=core2 -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m32 -I"C:\Python27\lib\site-packages\numpy\core\include" -I"C:\Python27\include" -I"C:\Python27\lib\site-packages\theano\gof" -L"C:\Python27\libs" -L"C:\Python27" -o C:\Documents and Settings\Administrator \.theano\compiledir_Windows-XP-5.1.2600 -SP3-x86_Family_6_Model_15_Stepping_13_ GenuineIntel-2.7.12-32\lazylinker_ext\lazylinker_ext.pyd C:\Documents and Settings\Administrator \.theano\compiledir_Windows-XP-5.1.2600-SP3-x86_ Family_6_Model_15_Stepping_13_GenuineIntel-2.7.12-32\lazylinker_ext\mod.cpp -lpython27-O 后面的pyd路径带空格, cpp源码文件也带了空格,
那么这里的解决方法就是, 翻到 C:\Python27\Lib\site-packages\theano\gof\cmodule.py 的第2281行 将原来的
cmd.extend(['-o', lib_filename]) #这个是那个pyd的输出位置, 带了空格 cmd.append(cppfilename) #这个就是那个cpp源码改为:
cmd.extend(['-o', '"%s"' % (lib_filename)]) cmd.append('"%s"' % (cppfilename))然后, 去cmd, 执行
>python >>> import theano 自动compile lazylinker_ext.pyd的markdown 代码块换行会丢失字符. 马拉个巴子的!!!!!!!!!!!!!!!!!!!!!!!!!!!