如何在 Windows 上构建 Scikit Learn?

4

当我在cmd中运行脚本:python setup.py install时,我收到以下错误信息:

ImportError: No module named sklearn._build_utils

安装之后:

  • Windows系统Python 2.7.2 64位版本
  • Enthought Canopy包含sciPy、NumPy和matplotlib
  • setuptools
  • scikit-learn-0.13.1.win32-py2.7
1个回答

8
如果您从二进制发行版安装,则不应尝试从源代码构建。只需重新安装scikit-learn的二进制包,您就可以在python shell中import sklearn
请注意,如果您使用Canopy的Python安装程序,则最好使用Canopy来安装scikit-learn:https://www.enthought.com/products/canopy/package-index/(尽管Canopy上可用的当前版本有点旧:0.11而不是0.13.1)。
如果要为自己的Pythonn 2.7安装scikit-learn,请从二进制软件包存储库Christoph Gohlke安装所有依赖项(scipy-stack元包应一次性提供所有依赖项)。
每当您有疑问时,都可以检查您正在运行哪个Python:
>>> import sys; print(sys.executable)

查看Python安装文件夹的位置。您还可以列出Python用于查找包的文件夹:

>>> print(sys.path)

对于scikit-learn或numpy,您可以执行以下操作:

>>> import sklearn; print(sklearn.__version__); print(sklearn.__path__)

并且:

>>> import numpy; print(numpy.__version__); print(numpy.__path__)

编辑:如果您真的想从源代码构建scikit-learn(例如从github存储库安装开发分支),则应该:

编辑2 修正一个拼写错误:将sys.__path__替换为sys.executable


我尝试在开发分支中从源代码构建scikit-learn。但是在构建时,我遇到了以下错误。我甚至安装了所有依赖项。c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: build\temp .win32-2.7\Release\sklearn\ensemble_gradient_boosting.o: bad reloc address 0x0 in section `.data' collect2.exe: error: ld returned 1 exit status - maheshakya
错误:命令“g++ -shared build\temp.win32-.7\Release\sklearn\ensemble_gradient_boosting.o -LC:\Python27\libs -LC:\Python27\PCbuild -Lbuild\temp.win32-2.7 - lpython27 -lmsvcr90 -o build\lib.win32-2.7\sklearn\ensemble_gradient_boosting.p yd”执行失败,退出状态为1....我该怎么办? - maheshakya
你好 @maheshakya,你是否成功地从源代码在Windows上进行了构建?你是如何解决错误的? - user961627
import sys; print(sys.path) 对我不起作用,但是print(sys.path)可以(python 2.7x) - Marc Maxmeister
确实,这是一个打字错误。我想说的是 sys.executable - ogrisel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接