相关疑难解决方法(0)

使用cython和mingw进行编译会产生gcc:错误:无法识别的命令行选项'-mno-cygwin'

我正在尝试使用mingw(64位)在win 7 64位中使用cython编译python扩展.
我正在使用Python 2.6(Active Python 2.6.6)和足够的distutils.cfg文件(将mingw设置为编译器)

执行时

> C:\Python26\programas\Cython>python setup.py build_ext --inplace
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,说gcc没有-mno-cygwin选项:

> C:\Python26\programas\Cython>python setup.py build_ext --inplace
running build_ext
skipping 'hello2.c' Cython extension (up-to-date)
building 'hello2' extension
C:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c hello2.c -o build\temp.win-amd64-2.6\Release\hello2.o
gcc: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

gcc是:

C:\>gcc --version
gcc (GCC) 4.7.0 20110430 (experimental)
Copyright (C) 2011 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)

我该怎么办呢?

python distutils mingw cython

114
推荐指数
3
解决办法
6万
查看次数

让distutils在正确的位置查找numpy头文件

在我的安装中,numpy arrayobject.h位于…/site-packages/numpy/core/include/numpy/arrayobject.h.我写了一个使用numpy的简单Cython脚本:

cimport numpy as np

def say_hello_to(name):
    print("Hello %s!" % name)
Run Code Online (Sandbox Code Playgroud)

我也有以下distutils setup.py(从Cython用户指南复制):

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("hello", ["hello.pyx"])]

setup(
  name = 'Hello world app',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)
Run Code Online (Sandbox Code Playgroud)

当我尝试构建时python setup.py build_ext --inplace,Cython尝试执行以下操作:

gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd \
-fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX \
-I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe \
-I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 …
Run Code Online (Sandbox Code Playgroud)

python distutils numpy cython

42
推荐指数
2
解决办法
2万
查看次数

使用include_path作为cythonize中的关键字的Cython编译错误

我有一个名为'test.pyx'的代码段:

import numpy as np
cimport numpy as np

print(np.arange(10))
Run Code Online (Sandbox Code Playgroud)

然后我写了两个setup.py来编译它们.第一个工作正常:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy as np

extensions = [
    Extension('test', ['test.pyx'], include_dirs = [np.get_include()]),
    ]

setup(
    ext_modules = cythonize(extensions)
    )
Run Code Online (Sandbox Code Playgroud)

而这个不起作用(这也来自http://docs.cython.org/src/reference/compilation.html上的一个例子):

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np


setup(
    ext_modules = cythonize('./test.pyx', include_path=[np.get_include()])
    )
Run Code Online (Sandbox Code Playgroud)

它说:./ test.c(346):致命错误C1083:无法打开包含文件:'numpy/arrayobject.h':没有这样的文件或目录.

我在Windows 64位上使用Python 3.3 64位,使用WinSDK 7.1.

python cython

9
推荐指数
1
解决办法
2818
查看次数

编译.pyx文件时缺少numpy/arrayobject.h

从enthought安装的树冠.在构建我的.pyx文件时,我收到此错误(后面跟着更多)

我是否需要easy_install其他软件包才能获得"开发"版本,因此我得到了 .h文件?

gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -DNDEBUG -g -O3 -arch x86_64 -I/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/include/python2.7 -c tsBinner.c -o build/temp.macosx-10.6-x86_64-2.7/tsBinner.o
tsBinner.c:314:31: error: numpy/arrayobject.h: No such file or directory
tsBinner.c:315:31: error: numpy/ufuncobject.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

更多背景

这在几个Linux安装下编译和运行,但不适用于我最近安装的Canopy发行版python

这是setup.py的内容

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("tsBinner",["tsBinner.pyx"])]

setup(
  name ='time stamp binner',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules 
)
Run Code Online (Sandbox Code Playgroud)

这是tsBinner.py的内容

from __future__ import division
import numpy as np
cimport numpy …
Run Code Online (Sandbox Code Playgroud)

python macos numpy

5
推荐指数
2
解决办法
6357
查看次数

致命错误:numpy / arrayobject.h:没有此类文件或目录

我的共享能力受到限制,因为这是我从Ubuntu 14.04移植到16.04的大量代码的一部分。

这应该是微不足道的,但是我却为此而苦苦挣扎。找不到numpy/arrayobject.h我在源文件中引用的#include <numpy/arrayobject.h>

我将尽力分享尽可能多的东西,看看是否有人可以指导我解决问题。

的Ubuntu

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial
Run Code Online (Sandbox Code Playgroud)

使

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Run Code Online (Sandbox Code Playgroud)

g ++

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Run Code Online (Sandbox Code Playgroud)

升级到

# g++ --version
g++ (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even …
Run Code Online (Sandbox Code Playgroud)

c++ python numpy g++

4
推荐指数
2
解决办法
6544
查看次数

标签 统计

python ×5

cython ×3

numpy ×3

distutils ×2

c++ ×1

g++ ×1

macos ×1

mingw ×1