Skip to main content
 首页 » 编程设计

python之在 Mac OS X 64 位上编译 S-Transform python 包装器

2025年05月04日7mate10pro

我正在尝试从 here 编译一个 s-transform python 包装器在我的 Mac 上(Mountain Lion,从 Macports 安装的 gcc45,通过 Enthought 64 位安装的 Python)。

我是科学用户而不是编译器专家,虽然它在我的 Linux 机器上开箱即用(只是将 int 更改为 npy_intp 并且PyArray_FromDims 到 PyArray_SimpleNew),我真的不知道如何在我的 Macbook 上到达那里...

所以我构建了这个 Makefile:

PYINCDIR = /Library/Frameworks/EPD64.framework/Versions/Current/include/python2.7 
NUMPYDIR = /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.7/site-packages/numpy/core/include/numpy CFLAGS = -O3 -I$(PYINCDIR) -I$(NUMPYDIR) -fPIC 
 
all: sinemodule.so stmodule.so 
 
sinemodule.so: sinemodule.o     $(CC) -shared -o $@ sinemodule.o 
 
stmodule.so: stmodule.o st.o    $(CC) -shared -o $@ stmodule.o st.o 
-lfftw3 

然后尝试“制作”,我得到:

cc -shared -o sinemodule.so sinemodule.o 
Undefined symbols for architecture x86_64: 
"_PyArg_ParseTuple", referenced from: 
  _sine_taper_wrap in sinemodule.o 
"_PyCObject_AsVoidPtr", referenced from: 
  _initsine in sinemodule.o 
"_PyCObject_Type", referenced from: 
  _initsine in sinemodule.o 
"_PyErr_Format", referenced from: 
  _initsine in sinemodule.o 
"_PyErr_Print", referenced from: 
  _initsine in sinemodule.o 
"_PyErr_SetString", referenced from: 
  _initsine in sinemodule.o 
"_PyExc_AttributeError", referenced from: 
  _initsine in sinemodule.o 
"_PyExc_ImportError", referenced from: 
  _initsine in sinemodule.o 
"_PyExc_RuntimeError", referenced from: 
  _initsine in sinemodule.o 
"_PyImport_ImportModule", referenced from: 
  _initsine in sinemodule.o 
"_PyObject_GetAttrString", referenced from: 
  _initsine in sinemodule.o 
"_Py_InitModule4_64", referenced from: 
  _initsine in sinemodule.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [sinemodule.so] Error 1 

也许这是一件非常基本的事情,但老实说,我什至不知道从哪里开始阅读来修复它......

为您的帮助干杯!

请您参考如下方法:

我刚找到这个废弃的帖子,想分享我的解决方案。

首先,正如您所做的那样,您需要找到 python 和 numpy include python 发行版的目录。

在我使用 Anaconda 1.9.1 的情况下,这是

PYINCDIR = /Users/dengemann/anaconda/include/python2.7/include 
NUMPYDIR = /Users/dengemann/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy/ 

其次,不能直接调用Makefile,要确保顶层目录下的setup.py是正确的。

在我的例子中,“darwin”没有得到明确支持,所以我添加了它。

# linux first 
if sys.platform in ['linux2', 'darwin']: 
    include_dirs = [os.path.join(NUMPYDIR, r'include/numpy')] 
    libraries=['fftw3'] 
    library_dirs=[] # assume we use default locations 

在运行 python setup.py install 完成这些修改后,工作和输出看起来符合预期。 卫生部, 丹尼斯