centos7 python3 安装matplotlib 和 scikit-learn

在CentOS7系统中安装matplotlib和scikit-learn时遇到导入错误,解决方案包括安装bzip2-devel解决scikit-learn的ImportError,确保tkinter和tk-devel的存在以解决matplotlib问题。详细步骤包括安装依赖库,下载Python3源码编译安装,最后使用pip3安装相关库。

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

scikit-learn

直接pip3 install scikit-learn能安装成功,但是import sklearn ,就会报错

ImportError: no module named '_bz2'

 

解决办法

yum install bzip2-devel

 

 

 matplotlib

在centos系统下,导入matplotlib时,出现ImportError: No module named '_tkinter'的错误,首先yum list installed | grep ^tk 
查看是否存在相应模块,通常原因是tkinter和tk-devel缺失。通过yum install -y tkinteryum install -y tk-devel下载相应模块

 

 

以上都弄好之后(否则弄一次编译一次麻烦),cd到python3目录重新编译python3

./configure

make

make install

 

python3安装可参考http://wzgdavid.iteye.com/admin/blogs/2381209

 

 

之后再centos6.5上又试了一遍

安装python3

  切换到root

一 先安装某些依赖库,再安装python

    这两个库是python3本身必须的,

    yum -y install zlib-devel

    yum -y install openssl-devel

    (这两个是matplotlib需要的)

    yum -y install tkinter   

    yum -y install tk-devel

    (sklearn 可能会报错,所以也装一下这个)

    yum -y install bzip2-devel

 

 

二 下载并安装python3

    去官方下载python3的source文件,就是tgz或者其他类型的压缩包

    或者

    wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

 

    把下载的压缩包解压,改一个简单的名字比如python3,然后cd到这个目录,依次运行

    ./configure

    make

    make install

 

    在终端输入python3,进入python3交互,安装成功

 

三 安装我们学过的第三方库

  

    pip3 install lxml

    pip3 install numpy

    pip3 install pandas

    pip3 install matplotlib

    pip3 install seaborn

    pip3 install scipy (sklearn依赖scipy)

    pip3 install scikit-learn (sklearn)

 

    第三方库安装完后,用import试一下是否能用

    如有问题,可能是linux系统缺某些依赖包,

    yum install 这些依赖包,之后

    再到python3安装目录,

    重新 make

         make install

 

(py3.9-tf2.4) C:\Users\XJY>pip install numpy pandas matplotlib sklearn notebook tensorflow-gpu==2.4.0rc2 -i https://pypi.doubanio.com/simple Looking in indexes: https://pypi.doubanio.com/simple Collecting numpy Downloading https://mirrors.cloud.tencent.com/pypi/packages/ea/2b/7fc9f4e7ae5b507c1a3a21f0f15ed03e794c1242ea8a242ac158beb56034/numpy-2.0.2-cp39-cp39-win_amd64.whl (15.9 MB) ---------------------------------------- 15.9/15.9 MB 6.8 MB/s eta 0:00:00 Collecting pandas Downloading https://mirrors.cloud.tencent.com/pypi/packages/2f/49/5c30646e96c684570925b772eac4eb0a8cb0ca590fa978f56c5d3ae73ea1/pandas-2.2.3-cp39-cp39-win_amd64.whl (11.6 MB) ---------------------------------------- 11.6/11.6 MB 7.8 MB/s eta 0:00:00 Collecting matplotlib Downloading https://mirrors.cloud.tencent.com/pypi/packages/57/68/c2feb4667adbf882ffa4b3e0ac9967f848980d9f8b5bebd86644aa67ce6a/matplotlib-3.9.4-cp39-cp39-win_amd64.whl (7.8 MB) ---------------------------------------- 7.8/7.8 MB 6.3 MB/s eta 0:00:00 Collecting sklearn Using cached https://mirrors.cloud.tencent.com/pypi/packages/46/1c/395a83ee7b2d2ad7a05b453872053d41449564477c81dc356f720b16eac4/sklearn-0.0.post12.tar.gz (2.6 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [15 lines of output] The 'sklearn' PyPI package is deprecated, use 'scikit-learn' rather than 'sklearn' for pip commands. Here is how to fix this error in the main use cases: - use 'pip install scikit-learn' rather than 'pip install sklearn' - replace 'sklearn' by 'scikit-learn' in your pip requirements files (requirements.txt, setup.py, setup.cfg, Pipfile, etc ...) - if the 'sklearn' package is used by one of your dependencies, it would be great if you take some time to track which package uses 'sklearn' instead of 'scikit-learn' and report it to their issue tracker
最新发布
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值