Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MinGW g+;找不到numpy\arrayobject.h+;在Windows中编译SWIG python包装时 在Debian发行版上,我成功地使用SWIG在C++中构建了Python模块。模块Amod可以在更复杂的python代码中成功导入,并且工作正常。以下是Linux上使用的编译: swig -c++ -python test5.i g++ -fPIC -c test5.cpp g++ -fPIC -c test5_wrap.cxx -I/usr/include/python2.7 g++ -shared test5.o test5_wrap.o -o _Amod.so_C++_Python_Numpy_Mingw_Swig - Fatal编程技术网

MinGW g+;找不到numpy\arrayobject.h+;在Windows中编译SWIG python包装时 在Debian发行版上,我成功地使用SWIG在C++中构建了Python模块。模块Amod可以在更复杂的python代码中成功导入,并且工作正常。以下是Linux上使用的编译: swig -c++ -python test5.i g++ -fPIC -c test5.cpp g++ -fPIC -c test5_wrap.cxx -I/usr/include/python2.7 g++ -shared test5.o test5_wrap.o -o _Amod.so

MinGW g+;找不到numpy\arrayobject.h+;在Windows中编译SWIG python包装时 在Debian发行版上,我成功地使用SWIG在C++中构建了Python模块。模块Amod可以在更复杂的python代码中成功导入,并且工作正常。以下是Linux上使用的编译: swig -c++ -python test5.i g++ -fPIC -c test5.cpp g++ -fPIC -c test5_wrap.cxx -I/usr/include/python2.7 g++ -shared test5.o test5_wrap.o -o _Amod.so,c++,python,numpy,mingw,swig,C++,Python,Numpy,Mingw,Swig,但是现在我想在Windows上重新编译它,我不知道我在做什么 我安装了numpy 1.7.0。和MinGW与g++,我在“path”环境变量中为swig添加了path,如swig文档中所述。我还为我的Python 2.7.5安装和Python.h添加了路径 我打开windows终端并键入: swig -c++ -Wall -python test5.i g++ -c -Wall test5.cpp 它编译起来没有问题。然后 g++ -c test5_wrap.cxx 致命错误:Python

但是现在我想在Windows上重新编译它,我不知道我在做什么

我安装了numpy 1.7.0。和MinGW与g++,我在“path”环境变量中为swig添加了path,如swig文档中所述。我还为我的Python 2.7.5安装和Python.h添加了路径

我打开windows终端并键入:

swig -c++ -Wall -python test5.i
g++ -c -Wall test5.cpp
它编译起来没有问题。然后

g++ -c test5_wrap.cxx 
致命错误:Python.h:没有这样的文件或目录
。我不明白,Python.h的路径不在path变量中!?所以我打字

g++ -c test5_wrap.cxx -I C:\Python27\include
致命错误:numpy\arrayobject.h:没有这样的文件或目录
。我也不明白,这个头存在于
C:\Python27\Lib\site packages\numpy\core\include\numpy\
中。然后我试着

g++ -c test5_wrap.cxx -I C:\Python27\include C:\Python27\Lib\site-packages\numpy\core\include\numpy\
同样的错误,所以我尝试:

g++ -c test5_wrap.cxx -I C:\Python27\include C:\Python27\Lib\site-packages\numpy\core\include\numpy\arrayobject.h
给出一大堆以相同的
致命错误开始的错误:numpy\arrayobject.h:没有这样的文件或目录

如何解决这个问题?MinGW+SWIG+g++是python模块编译的正确方向吗

非常感谢

F.M

编辑:同时,我还尝试使用以下setup.py使用distutils编译此python模块:

# -*- coding: utf-8 -*-
"""
Created on Wed Oct 23 17:01:51 2013

@author: Florian
"""
from distutils.core import setup, Extension


Amod = Extension('_Amod',
                           sources=['test5_wrap.cxx', 'test5.cpp'],
                           )

setup (name = 'Amod',
       version = '0.1',
       author      = "FM",
       description = """Come on""",
       ext_modules = [Amod],
       py_modules = ["Amod"],
       )
并使用以下工具进行编译:

python setup.py build_ext --compiler=mingw32 --swig-opts="-c++ -I :C/Python27/include -I :C/Python27/Lib/site-packages/numpy/core/include/"
还有这个该死的错误:

running build_ext
building '_Amod' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c test5_wrap.cxx -o build\temp.win32-2.7\Rel
ease\test5_wrap.o
test5_wrap.cxx:3045:31: fatal error: numpy/arrayobject.h: No such file or directory
 #include <numpy/arrayobject.h>
运行build\u ext
建筑物“阿摩德”扩建部分
C:\MinGW\bin\gcc.exe-mdll-O-Wall-IC:\Python27\include-IC:\Python27\PC-C test5\u wrap.cxx-O build\temp.win32-2.7\Rel
ease\test5\u wrap.o
test5_wrap.cxx:3045:31:致命错误:numpy/arrayobject.h:没有这样的文件或目录
#包括

我在谷歌上搜索了错误
对我第一次尝试得到的_imp\u Py…
的未定义引用,但是人们谈论缺少链接库,我不知道应该链接哪个库以及为什么。这有点超出了我的技能。

尝试将其更改为
-ic:\Python27\include-ic:\Python27\Lib\site packages\numpy\core\include
。需要这些路径,以便gcc知道在哪里搜索include头


在*nix环境中,gcc在查找包含头时可能会查找环境变量和其他隐式搜索路径,这可能就是它成功编译的原因。但是,在windows mingw上,您必须明确指定这些路径,使其看起来位于正确的位置。

尝试将其更改为
-ic:\Python27\include-ic:\Python27\Lib\site packages\numpy\core\include
。需要这些路径,以便gcc知道在哪里搜索include头


在*nix环境中,gcc在查找包含头时可能会查找环境变量和其他隐式搜索路径,这可能就是它成功编译的原因。然而,在Windows MINW上,你必须明确地指定这些路径,以便它在正确的位置上查找。

< P>我在编译C++代码时在CygWin中遇到了同样的问题。解决方案是安装python2-devel和python2-numpy,然后使用命令“python-msite”查看python安装目录。使用以下find命令查找头文件:find/usr/lib/python2.7-name“*.h”。头文件位于/usr/lib/python2.7/site-packages/numpy/core/include目录下。将此路径包含如下选项:g++命令:-I/UR/LB/Python 2.7/站点包/ NUMPY/CARC/包含。

< P>在CigWin编译C++代码时,我遇到了同样的问题。解决方案是安装python2-devel和python2-numpy,然后使用命令“python-msite”查看python安装目录。使用以下find命令查找头文件:find/usr/lib/python2.7-name“*.h”。头文件位于/usr/lib/python2.7/site-packages/numpy/core/include目录下。使用以下Include选项将此路径包括到g++命令中:-I/usr/lib/python2.7/site packages/numpy/core/Include。

Ok,它会编译。我得到一个警告:
:警告消息:使用不推荐的NumPy API,禁用它#定义NPY(不推荐的)API(不推荐的)API(不推荐的)版本#定义NPY(不推荐的)API(不推荐的)API(不推荐的)版本#“
@fmollica不知道这是怎么回事。也许绑定使用了一些不推荐使用的函数,这些函数将在将来的版本中逐步淘汰?可能想用谷歌搜索一下numpy文档或回购协议的提交日志。你应该找到一些关于warningOk的东西,它是编译的,我相信我可以在-I。。。。我得到一个警告:
:警告消息:使用不推荐的NumPy API,禁用它#定义NPY(不推荐的)API(不推荐的)API(不推荐的)版本#定义NPY(不推荐的)API(不推荐的)API(不推荐的)版本#“
当我完成最后一步时:
g++-sharedtest5.o test5\u wrap.o-o\u Amod.pyd
它给了我很多错误`未定义的引用
\u imp\u Py…
就像某个库在其中丢失了
g++-sharedtest5.o test5\u wrap.o-o\u Amod.pyd-L C:\Python27\libs-lpython27
。您还可以使用完全限定的路径传递它:
g++-shared test5.o test5\u wrap.o-o\u Amod.pyd C:/Python27/libs/Python27.lib
。两天的血泪终于结束了。正确的格式确实是
g++-Wall-shared-ic:\Python27\include-ic:\Python27\Lib\site packages\numpy\core\include\test5.o test5\u wrap.o\u Amod.pyd-lc:/Python27/libs/-lpython27
。再次感谢你。还需要注意的是,我在这个SWIG过程中遇到的一个bug是我的.I文件的错误编码,它们需要小心地用utf-8编码。再次感谢。好的,它编译好了。我得到一个警告:
:警告消息:使用不推荐的NumPy API,禁用它#定义NPY(不推荐的)API(不推荐的)API(不推荐的)API(版本)#定义NPY(不推荐的)API(不推荐的)