centos6.4下scikit-learn安装经历

本文提供了一套详细的Scikit-learn安装流程,包括必要软件包的安装、配置pip、更新NumPy和SciPy等依赖项,以及最终安装Scikit-learn的方法。
1、安装必要的包
yum install lapack lapack-devel blas blas-devel
yum install numpy
yum install scipy

如果没有安装gcc,要先安装gcc 和g++
yum install gcc  
yum install gcc-c++  

如果不安装lapack lapack-devel blas blas-devel 会报错(截取一部分):

lapack_opt_info:
  openblas_lapack_info:
    libraries openblas not found in ['/usr/local/lib64', '/usr/local/lib', '/usr/lib64', '/usr/lib']
    NOT AVAILABLE
  lapack_mkl_info:
  mkl_info:
    libraries mkl,vml,guide not found in ['/usr/local/lib64', '/usr/local/lib', '/usr/lib64', '/usr/lib']
    NOT AVAILABLE

warnings.warn(AtlasNotFoundError.__doc__)
  lapack_info:
    libraries lapack not found in ['/usr/local/lib64', '/usr/local/lib', '/usr/lib64', '/usr/lib']
    NOT AVAILABLE
...
...
numpy.distutils.system_info.NotFoundError: no lapack/blas resources found


2、安装pip

下载pip
https://pip.pypa.io/en/latest/installing/
yum install -y openssl openssl-devel
python get-pip.py

或者

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
[root@test77 ~]# pip -V
pip 9.0.1 from /usr/lib/python2.6/site-packages (python 2.6)


[root@testserver4 ~]# python get-pip.py
Collecting pip
  Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 350kB/s
Collecting wheel
  Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB)
    100% |████████████████████████████████| 65kB 5.0MB/s
Collecting argparse (from wheel)
  Downloading argparse-1.4.0-py2.py3-none-any.whl
Installing collected packages: pip, argparse, wheel
Successfully installed argparse-1.4.0 pip-7.1.2 wheel-0.26.0
/tmp/tmpcBdh5G/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90:
InsecurePlatformWarning: A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.



输入pip命令如果能看到pip的介绍信息,那么证明安装成功了。

3、更新pip
pip install --upgrade pip

Scikit-learn要求
Scikit-learn requires:
    Python (>= 2.6 or >= 3.3),
    NumPy (>= 1.6.1),
    SciPy (>= 0.9).

4、升级numPy和scipy
pip install -U numPy
pip install -U scipy

5、安装sk-learn  
pip install -U scikit-learn

提示安装成功,那就可以开始scikit-learn之旅

基本上按照以上步骤都能安装好。


扩展:
指定版本安装
pip install scipy==0.16.1

python下如何安装.whl包?
pip install wheel
python下如何安装.whl包
之后pip install 包名字.whl 即可安装某模块包


参考:
http://www.centoscn.com/image-text/install/2014/0403/2715.html
http://scikit-learn.org/stable/install.html
http://blog.youkuaiyun.com/lingfeng892/article/details/50425547
http://stackoverflow.com/questions/7496547/does-python-scipy-need-blas/9173550#9173550
但是我pip的时候却报错:Installing build dependencies ... error error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [71 lines of output] Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation == "CPython"' don't match your environment Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation != "CPython"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment Collecting setuptools Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl (1.2 MB) Collecting wheel Using cached https://pypi.tuna.tsinghua.edu.cn/packages/0b/2c/87f3254fd8ffd29e4c02732eee68a83a1d3c346ae39bc6822dcbcb697f2b/wheel-0.45.1-py3-none-any.whl (72 kB) Collecting Cython>=0.28.5 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/94/65ba40faeafe74845ba22b61aff7d73475671c3bd24bffc6cba53f3b0063/cython-3.1.2-cp313-cp313-win_amd64.whl (2.7 MB) ---------------------------------------- 2.7/2.7 MB 11.0 MB/s eta 0:00:00 Collecting numpy==1.17.3 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b6/d6/be8f975f5322336f62371c9abeb936d592c98c047ad63035f1b38ae08efe/numpy-1.17.3.zip (6.4 MB) ---------------------------------------- 6.4/6.4 MB 11.1 MB/s eta 0:00:00 Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Preparing metadata (pyproject.toml) did not run successfully. exit code: 1 [28 lines of output] Running from numpy source directory. <string>:418: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates Traceback (most recent call last): File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() ~~~~^^ File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 149, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "C:\Users\18982\AppData\Local\Temp\pip-build-env-iylv62ta\overlay\Lib\site-packages\setuptools\build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() ~~~~~~~~~~~~~~^^ File "C:\Users\18982\AppData\Local\Temp\pip-build-env-iylv62ta\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\18982\AppData\Local\Temp\pip-build-env-iylv62ta\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup exec(code, locals()) ~~~~^^^^^^^^^^^^^^^^ File "<string>", line 443, in <module> File "<string>", line 422, in setup_package File "C:\Users\18982\AppData\Local\Temp\pip-install-cnhfnw94\numpy_33d7182cc1bd44368e579191210a5ae4\numpy\distutils\__init__.py", line 6, in <module> from . import ccompiler File "C:\Users\18982\AppData\Local\Temp\pip-install-cnhfnw94\numpy_33d7182cc1bd44368e579191210a5ae4\numpy\distutils\ccompiler.py", line 111, in <module> replace_method(CCompiler, 'find_executables', CCompiler_find_executables) ^^^^^^^^^ NameError: name 'CCompiler' is not defined. Did you mean: 'ccompiler'? [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed Encountered error while generating package metadata. See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (base) (.venv) PS D:\Python\Projects\SymbolicRegression> pip uninstall scikit-learn Found existing installation: scikit-learn 1.7.1 Uninstalling scikit-learn-1.7.1: Would remove: d:\python\projects\symbolicregression\.venv\lib\site-packages\scikit_learn-1.7.1.dist-info\* d:\python\projects\symbolicregression\.venv\lib\site-packages\sklearn\* Proceed (Y/n)? y Successfully uninstalled scikit-learn-1.7.1 (base) (.venv) PS D:\Python\Projects\SymbolicRegression> pip install scikit-learn==0.20.4 -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting scikit-learn==0.20.4 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/a0/5ec20d7e460d8ebde9ec5e40cda4339c5f546871c3a5bf9228f615b25618/scikit-learn-0.20.4.tar.gz (11.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.7/11.7 MB 11.5 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [29 lines of output] <string>:12: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. Partial import of sklearn during the build process. Traceback (most recent call last): File "<string>", line 153, in get_numpy_status ModuleNotFoundError: No module named 'numpy' Traceback (most recent call last): File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() ~~~~^^ File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python\Projects\SymbolicRegression\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 149, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "C:\Users\18982\AppData\Local\Temp\pip-build-env-uqmyyyrx\overlay\Lib\site-packages\setuptools\build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() ~~~~~~~~~~~~~~^^ File "C:\Users\18982\AppData\Local\Temp\pip-build-env-uqmyyyrx\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\18982\AppData\Local\Temp\pip-build-env-uqmyyyrx\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup exec(code, locals()) ~~~~^^^^^^^^^^^^^^^^ File "<string>", line 250, in <module> File "<string>", line 238, in setup_package ImportError: Numerical Python (NumPy) is not installed. scikit-learn requires NumPy >= 1.8.2. Installation instructions are available on the scikit-learn website: http://scikit-learn.org/stable/install.html [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
07-28
(.venv) PS D:\PycharmProjects\pythonProject4> pip install scikit-learn==0.23.2 Collecting scikit-learn==0.23.2 Downloading scikit-learn-0.23.2.tar.gz (7.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.2/7.2 MB 10.5 MB/s 0:00:00 Installing build dependencies ... error error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [63 lines of output] Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation == "CPython"' don't match your environment Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation != "CPython"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment Collecting setuptools Using cached setuptools-80.9.0-py3-none-any.whl.metadata (6.6 kB) Collecting wheel Using cached wheel-0.45.1-py3-none-any.whl.metadata (2.3 kB) Collecting Cython>=0.28.5 Downloading cython-3.1.4-cp312-cp312-win_amd64.whl.metadata (5.1 kB) Collecting numpy==1.17.3 Downloading numpy-1.17.3.zip (6.4 MB) ---------------------------------------- 6.4/6.4 MB 10.6 MB/s 0:00:00 Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Preparing metadata (pyproject.toml) did not run successfully. exit code: 1 [25 lines of output] Running from numpy source directory. <string>:418: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates Traceback (most recent call last): File "D:\PycharmProjects\pythonProject4\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module> main() File "D:\PycharmProjects\pythonProject4\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\PycharmProjects\pythonProject4\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\v\AppData\Local\Temp\pip-build-env-wllh6wa5\overlay\Lib\site-packages\setuptools\build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() File "C:\Users\v\AppData\Local\Temp\pip-build-env-wllh6wa5\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) File "C:\Users\v\AppData\Local\Temp\pip-build-env-wllh6wa5\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 443, in <module> File "<string>", line 422, in setup_package File "C:\Users\v\AppData\Local\Temp\pip-install-u5gldzm0\numpy_2c497d51b8b642f08971ea76b9e40226\numpy\distutils\__init__.py", line 6, in <module> from . import ccompiler File "C:\Users\v\AppData\Local\Temp\pip-install-u5gldzm0\numpy_2c497d51b8b642f08971ea76b9e40226\numpy\distutils\ccompiler.py", line 111, in <module> replace_method(CCompiler, 'find_executables', CCompiler_find_executables) ^^^^^^^^^ NameError: name 'CCompiler' is not defined. Did you mean: 'ccompiler'? [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed Encountered error while generating package metadata. See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. (.venv) PS D:\PycharmProjects\pythonProject4>
最新发布
09-28
<think>好的,用户现在需要了解在CentOS 7系统上使用Anaconda安装scikit-learn的步骤。首先,我要回忆一下CentOS 7的基本情况,它可能比较老旧,默认的软件包可能不够新,所以使用Anaconda来管理Python环境是个不错的选择,因为Anaconda自带很多科学计算的库,可以避免依赖问题。 用户可能已经安装了Anaconda,但需要确认。如果没有安装的话,我需要先指导他们安装Anaconda。考虑到CentOS 7可能没有图形界面,所以步骤需要全在终端完成。安装Anaconda通常是从官网下载脚本,然后运行bash安装,记得要添加到PATH中,或者让安装程序自动添加。 接下来是创建虚拟环境。用户可能已经有自己的项目环境,或者需要新建一个。使用conda创建环境可以隔离不同项目的依赖,避免版本冲突。这里需要指定Python版本,比如3.8,因为CentOS 7的默认Python可能比较旧,但Anaconda支持较新的版本。 然后是安装scikit-learn。这里要分两种情况,用conda安装或者pip安装。通常conda更推荐,因为conda会处理非Python的依赖,比如numpy和scipy可能依赖的底层库。不过如果用户习惯用pip,也可以,但要确保依赖项已经正确安装。可能需要先安装numpy和scipy,但conda应该会自动处理这些。 安装完成后需要验证,比如进入Python环境导入sklearn并检查版本。这一步很重要,因为有时候安装可能看起来成功,但实际导入失败,可能是路径问题或者依赖项缺失。 另外,用户可能遇到问题,比如安装速度慢,这时候可以建议更换conda的镜像源,比如国内的清华源或者阿里源。还有可能环境变量没有正确设置,导致conda命令找不到,这时候需要检查.bashrc或者手动初始化conda。 需要注意的还有,CentOS 7的glibc版本可能较低,如果用户安装的某些包需要更高版本的glibc,可能会出问题。不过Anaconda的包通常会处理这些依赖,所以可能不会有问题,但需要提醒用户如果遇到相关错误,可能需要更新系统库或者使用conda的特定版本。 最后,用户可能需要安装特定版本的scikit-learn,这时候要说明如何指定版本号,比如conda install scikit-learn=1.0.2。或者用户可能已经安装了,需要升级,这时候可以用--upgrade参数。 总结步骤应该是:安装Anaconda → 创建环境 → 安装scikit-learn → 验证。同时提供常见问题解决方法和注意事项,比如换源、环境激活等。确保用户能够一步步跟着操作,避免遗漏关键步骤。</think>以下是在 CentOS 7 系统中使用 Anaconda 安装 scikit-learn 的详细指南: --- ### **一、安装准备** #### 1. 确认 Anaconda 已安装 ```bash # 查看 Anaconda 版本 conda --version # 若未安装,从官网下载脚本(推荐使用清华镜像加速) wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.03-Linux-x86_64.sh ``` #### 2. 安装 Anaconda(若未安装) ```bash # 执行安装脚本 bash Anaconda3-2023.03-Linux-x86_64.sh # 按照提示操作,安装完成后激活环境 source ~/.bashrc # 或重启终端 ``` --- ### **二、创建虚拟环境(推荐)** ```bash # 创建名为 sklearn_env 的独立环境,指定 Python 3.8 conda create -n sklearn_env python=3.8 # 激活环境 conda activate sklearn_env ``` --- ### **三、安装 scikit-learn** #### **方法 1:通过 Conda 安装(自动处理依赖)** ```bash conda install scikit-learn ``` #### **方法 2:通过 Pip 安装** ```bash # 先确保已安装基础科学计算库 conda install numpy scipy # 再通过 pip 安装 pip install scikit-learn ``` --- ### **四、验证安装** ```python # 启动 Python 解释器 python # 在 Python 中测试 >>> import sklearn >>> print(sklearn.__version__) # 应输出版本号如 1.3.0 >>> sklearn.show_versions() # 查看完整依赖信息 ``` --- ### **五、常见问题解决** #### **1. 安装速度慢** ```bash # 配置清华 Conda 镜像源 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes ``` #### **2. 环境激活失败** ```bash # 若出现 conda: command not found echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc source ~/.bashrc ``` #### **3. 依赖冲突** ```bash # 强制清理旧版本 conda remove --force scikit-learn pip uninstall scikit-learn # 重新安装 conda install -c conda-forge scikit-learn ``` --- ### **六、升级 scikit-learn** ```bash # Conda 升级 conda update scikit-learn # Pip 升级 pip install --upgrade scikit-learn ``` --- ### **注意事项** 1. **CentOS 7 兼容性** 若使用较新版本的 scikit-learn,需确保: - glibc >= 2.17(CentOS 7 默认 2.17) - 通过 `conda install gxx_linux-64` 安装 C++ 编译器支持 2. **GPU 加速** 如需 GPU 加速支持,需额外安装: ```bash conda install cupy # NVIDIA GPU 支持 pip install scikit-learn-intelex # Intel CPU/GPU 加速 ``` 3. **最小化安装** 对资源受限环境可使用最小安装: ```bash conda install scikit-learn=1.0.2 --no-deps ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值