在mac上安装scikit-learn

来源:互联网 发布:如何联系淘宝达人 编辑:程序博客网 时间:2024/06/06 08:40

我的系统是OS X EI Capitan,最近在安装python的机器学习工具包scikit-learn,现把经历的一些过程记录一下:


安装scikit-learn前需要先装好python、numpy和scipy,其中python是mac自带的,版本2.6以上就可以。


1)安装numpy:

可以通过sudo brew install numpy的方式或者pip install numpy,但是我在这种方式下,下载的时候报错了,和pip仓库的服务器连接不稳定,于是我改用先到sourceforge下载numpy,然后:


解压,进入解压后的目录

tar -xzf numpy-1.11.1.tar.gz
cd numpy-1.11.1


执行安装:

python setup.py install


等安装完后,没有报错的话,检测一下是否安装好了

python -c "import numpy"

2)安装scipy:

同样,因为网速问题,我选择先下载好scipy安装包再python setup.py install


但是报错了,意思是我的mac没有安装gfortran编译器(事后记载,所以没截图),用

brew install gfortran
系统提示:

Error: No available formula with the name "gfortran"GNU Fortran is now provided as part of GCC, and can be installed with: brew install gcc

gfortran在现在的gcc版本里已经集成到gcc里面了,要安装gfortran的话可以重新安装一下gcc,但是这里我们只安装一下gfortran,gfortran在mac上可以考虑下载gfortran-6.1-ElCapitan.dmg,但是mac报错:


mac打不开这个镜像,我用网上说的Disk Utility的方法也不管用


考虑另外一种方式,从sourceforge下载gfortran压缩包 gfortran-5.3-bin.tar.gz,将该压缩包解压到指定目录,这里是根目录

tar -xzf gfortran-5.3-bin.tar -C /
解压后的目录由于与根目录下的bin lib相同,所以会将解压出来的文件合并到/bin /lib等中去

检测gfortran是否安装成功,通过查看其版本信息

gfortran --version

3)安装scikit-learn


安装好先行条件后,最后是安装scikit-learn了,这一步比较顺利

pip install scikit-learn

可以看到scikit-learn已经安装好了

python -c "import sklearn"





0 0
原创粉丝点击