简体   繁体   English

如何安装numpy的32位版本

[英]How do I install a 32-bit version of numpy

After much effort, I've finally got matplotlib, and all its dependencies, working harmoniously on Snow Leopard 10.6.8. 经过大量的努力,我终于有了matplotlib及其所有依赖项,在Snow Leopard 10.6.8上和谐地工作。 I'd now like to tweak its configuration slightly to allow me to use my 32-bit installation of wxPython as its backend. 现在,我想稍微调整一下它的配置,以允许我将wxPython的32位安装用作其后端。 The problem is that numpy (required by matplotlib) won't import when I use my 32-bit installation of Python 2.7.3 (python.org version). 问题是当我使用32位安装的Python 2.7.3(python.org版本)时,numpy(matplotlib要求)将不会导入。 Googling for an hour or so has led me to believe that numpy can be built and installed as 32-bit by specifying CFLAGS and LDFLAGS inconjunction with setup.py. 谷歌搜索一个小时左右,使我相信可以通过与setup.py一起指定CFLAGS和LDFLAGS来将numpy构建和安装为32位。 I'm not clear on what these flags do, and not surprisingly I've had no success using them. 我不清楚这些标志的作用,并不奇怪,我使用它们并没有成功。 This is what I tried from within the downloaded numpy folder: 这是我在下载的numpy文件夹中尝试的方法:

$ CLFLAGS=-m32 LDFLAGS=-m32 python setup.py install

I get a few error messages, but a 64-bit compatible version of numpy does arrive in my sitepackages folder. 我收到一些错误消息,但是numpy的64位兼容版本确实到达了我的sitepackages文件夹。 When I use the 32-bit interpreter however I get an error: 但是,当我使用32位解释器时,出现错误:

ImportError: dynamic module does not define init function (initmultiarray)

Am I right to think I can build a 32-bit numpy? 我认为我可以构建32位numpy吗?

I just spent a couple days looking around and pulling my hair out so I thought I'd contribute here to what I found... 我只是花了几天的时间四处张望,把头发拔了出来,所以我想我会在这里为我所发现的做出贡献...

I had the same problem but just setting the flags would not work for me (but this is needed indeed) ... In my case I have a seperate 32-bit version of python, so I did: 我遇到了同样的问题,但仅设置标志对我来说不起作用(但确实需要这样做)...就我而言,我有一个单独的32位版本的python,所以我做到了:

CFLAGS="-m32" LDFLAGS="-m32" /util/linux32/bin/python setup.py install --prefix=/util/science/gfortran-4.4.6/linux32/ CFLAGS =“-m32” LDFLAGS =“-m32” / util / linux32 / bin / python setup.py install --prefix = / util / science / gfortran-4.4.6 / linux32 /

(don't worry about my gfortran thing in the prefix, lucky me had to test different compilers.. ;) ) (不必担心前缀中的gfortran东西,幸运的是我不得不测试不同的编译器。;)

but then I would get an error, the last line would say: "RuntimeError: Broken toolchain: cannot link a simple C program" 但是然后我会得到一个错误,最后一行会说:“ RuntimeError:断开的工具链:无法链接简单的C程序”

but if I scrolled up I had: 但是如果我向上滚动,就会有:

gcc -pthread _configtest.o -o _configtest gcc -pthread _configtest.o -o _configtest

_configtest.o: could not read symbols: File in wrong format _configtest.o:无法读取符号:文件格式错误

collect2: ld returned 1 exit status collect2:ld返回1退出状态

_configtest.o: could not read symbols: File in wrong format _configtest.o:无法读取符号:文件格式错误

collect2: ld returned 1 exit status collect2:ld返回1退出状态

failure. 失败。

removing: _configtest.c _configtest.o 删除:_configtest.c _configtest.o

and as you can see, no "-m32" flag in that call to gcc... 如您所见,对gcc的调用中没有“ -m32”标志。

I tracked it back to the distutils install ; 我追溯到distutils安装; for me in there: /util/linux32/lib/python2.7/distutils/ccompiler.py 在那对我来说:/util/linux32/lib/python2.7/distutils/ccompiler.py

and there is probably a more elegant solution than that, like getting the cflags value directly, but I am not a python girl so not sure how.. ;) I could probably figure it out but all I care about right now is to finally install numpy in 32-bit mode.. so anyways... line 693 of this python code, I changed 并且可能有一个比这更优雅的解决方案,例如直接获取cflags值,但是我不是python女孩,所以不确定如何..;)我可能会弄清楚,但是我现在关心的只是最终安装numpy在32位模式下..所以无论如何...此python代码的第693行,我更改了

runtime_library_dirs=None, debug=0, extra_preargs=None,

to

runtime_library_dirs=None, debug=0, extra_preargs=['-m32'],

(in the function link_executable ; in case you have a different version of python... ) (在link_executable函数中;如果您使用的是其他版本的python ...)

and voila... numpy in installed succesfully on a 64-bit machine in 32-bit mode.. I assume this would work for other modules too since it is related to distutils, not numpy.. ;) 和voila ... numpy已成功在32位模式下安装在64位计算机上。.我认为这也适用于其他模块,因为它与distutils相关,而不是numpy ..;)

hope this can help someone in the future and save some time! 希望这可以在将来对某人有所帮助并节省一些时间!

Eve-Marie 夏娃 - 玛丽·

You could try using the free version of EPD (or the full version is free if you're in academia): 您可以尝试使用EPD的免费版本(如果您处于学术界,则可以免费使用完整版本):

http://www.enthought.com/products/epd_free.php/ http://www.enthought.com/products/epd_free.php/

This has a 32-bit version for mac with all of the key scientific stack packages including scipy, numpy and matplotlib. 它具有适用于Mac的32位版本,其中包含所有关键的科学堆栈软件包,包括scipy,numpy和matplotlib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM