如何在Windows上安装numpy for PyPy?

2024-05-12 10:52:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚在Windows上安装了PyPy,在运行的一些模拟代码中看到了大约10倍的速度提升。我也希望在使用numpy的代码上看到类似的结果。然而,我不是一个有经验的Python程序员,我发现instructions很难理解。有人知道在Windows上安装numpy for PyPy是否可行吗?如果可以,最简单的方法是什么?

说明书提供了两种选择。

选项1

If you have pip (the command-line assumes that it finds the pip belonging to PyPy, not the one from CPython):

pip install git+https://bitbucket.org/pypy/numpy.git

这看起来是个不错的选择,但在我解压缩到的目录结构中找不到pip

选项2

Alternatively, the direct way:

git clone https://bitbucket.org/pypy/numpy.git
cd numpy
pypy setup.py install

我在Windows上没有git,但我也怀疑这个选项可能涉及从https://bitbucket.org/pypy/numpy.git编译源代码,甚至在Windows上不可能(或者需要大量的黑客操作)。

编辑

根据the answer below或问题How do I install pip on Windows?this answer中的说明,通过https://sites.google.com/site/pydatalog/python/pip-for-windows安装pip失败,原因是ConnectionError: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /packages/py2.py3/p/pip/pip-1.5.4-py2.py3-none-any.whl (Caused by <class 'httplib.BadStatusLine'>: '')。参见,例如this bug report。然而,通过在解决方案资源管理器的Python环境下右键单击PyPy 2.7,选择installpython Package,我可以通过Microsoft Visual StudioPTVS安装pip。这无法安装numpy(另一个连接错误),但确实安装了pip。

现在有了pip,我尝试使用pip install git+https://bitbucket.org/pypy/numpy.git在命令行上安装numpy。首先我需要安装git来完成这项工作。。。没问题。但后来失败了

building library "npymath" sources
No module named numpy.distutils.msvccompiler in numpy.distutils; trying from distutils
error: Unable to find vcvarsall.bat

我不熟悉Python包的安装,也不知道这意味着什么。我确实安装了VisualStudio 2012,其中安装了C++编译器,但另一方面,Python 3.3的{a9}(我现在使用2.7)似乎暗示不需要C++编译器。

编辑

这似乎与pip安装无关。遵循选项2

git clone https://bitbucket.org/pypy/numpy.git
cd numpy
pypy setup.py install

我仍然得到Unable to find vcvarsall.bat。但是,如果将环境变量VS90COMNTOOLS设置到适当的目录,则可以从this answer中得到提示,vcvarsall.bat。在我的例子中,我有VS2012,所以适当的行是

set VS90COMNTOOLS=%VS110COMNTOOLS%

现在可以找到编译器,但是有一个编译错误

_configtest.c
_configtest.c(4) : error C2061: syntax error : identifier 'npy_check_sizeof_type'
_configtest.c(4) : error C2059: syntax error : ';'
_configtest.c(7) : error C2065: 'npy_check_sizeof_type' : undeclared identifier error:

看起来这是一个在编译过程中生成的文件,可能根本不需要构建。不过,我想我现在可能真的被卡住了。。。


Tags: installpipthetohttpsorggitnumpy
2条回答

我不认为numpy会有什么不同:Pypy的设计目的是加速本地python代码,而numpy是用C(以及python)编写的,并且可能已经编译为最大化速度。

对于第一个选项,您应该从

https://sites.google.com/site/pydatalog/python/pip-for-windows

之后,您应该在environment变量PATH中添加pip的路径。
最后,应该使用命令提示符并使用

pip install git+https://bitbucket.org/pypy/numpy.git

相关问题 更多 >