ubuntu 安装 scikit-learn的注意事项

本文详细介绍了scikit-learn的安装步骤与注意事项,包括针对不同Python版本的选择、依赖库安装、解决常见错误等,帮助读者顺利搭建机器学习环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、主要python的版本

scikit-learn is tested to work underPython 2.6, Python 2.7, and Python 3.4. (using the same codebase thanks to an embedded copy of six).It should also work with Python 3.3.

The required dependencies to build the software areNumPy >= 1.6.1, SciPy >= 0.9 and a working C/C++ compiler.

总结:装scikit-learn 必须要注意自己python的版本,我的系统装了python2.7和python3.2.3,查了一下官网,python3.2.3没有对应的scikit-learn。谨记,一定根据自己系统python的版本来安装scikit-learn。

2、安装scikit-learn步骤。

1、首先需要安装Cython,网上下载后进行本地安装 python setup.py install。(官网没讲,不过我还是装了,参考自http://blog.youkuaiyun.com/lanbing510/article/details/41125189)

2、参照官网的做法:http://scikit-learn.org/stable/developers/advanced_installation.html#install-by-distribution。主要是安装依赖项之类的,官网用源码安装,我试了一下,在我的机子上报错,所以,安装完依赖项之后,先不要用源码安装。

3、虽然根据官网去安装,在安装的过程中还是会遇到很多问题,我遇到的问题如下,及相对应的解决方案。

1、根据官网的步骤,在安装完依赖项,比如numpy,scipy之后,然后下载源码,进行源码安装,

python setup.py build
sudo python setup.py install

但是,我跟官网的步骤做,却报错。因为我系统python解释器默认是python2.7,所以才是python setup.py build。如果,是想在python3.4下安装scikit-learn,那么相应的命令应该是python3 setup.py build。

python setup.py build 报错信息如下:


后来在网上搜了方法,在依赖项装完之后,直接用命令sudo apt-get install python-sklearn安装。

2、undefined symbol: ATL_chemv 错误

import sklearn 没出错,说明sklearn已经装好。

但是,from sklearn import preprocessing 出现错误:

ImportError: /usr/lib/liblapack.so.3gf: undefined symbol: ATL_chemv


解决方案:

http://stackoverflow.com/questions/8917977/installing-lapack-for-numpy

sudo apt-get remove libopenblas-base
亲测有效。

至此,在我机器上,基于python2.7的scikit-learn安装完毕


3、安装的过程中还容易遇到如下错误:

ImportError: No module named _check_build


解决方案:可以参考博客 http://blog.youkuaiyun.com/m53931422/article/details/42489897。ps,我参考该博客并没有解决问题。


lhj@raspberrypi:~ $ # 先卸载残留文件 pip uninstall scikit-learn -y # 使用清华镜像源加速安装 pip install scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade --force-reinstall error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. For more information visit http://rptl.io/venv note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. For more information visit http://rptl.io/venv note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值