当前位置: 代码迷 >> 综合 >> Windows安装python包numpy、SciPy、scikit-learn
  详细解决方案

Windows安装python包numpy、SciPy、scikit-learn

热度:74   发布时间:2023-12-19 04:22:48.0

基于Tsinghua anaconda镜像的下载


更新:

使用pip方式安装更快:

pip install numpy
pip install scipy
pip install scikit-learn

1、镜像配置

在cmd窗口,运行

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

这里只是配置anaconda (一个python科学计算包)的仓库镜像来安装里边的包。

2、安装numpy/scipy/scikit-learn

conda install numpy
conda install scipy
conda install scikit-learn

如果安装出现失败,提示无法访问****,可以通过使用命令行(管理员)来打开,重新输入指令,即可。

C:\Windows\system32>pip3 install --ignore-installed --upgrade -U scikit-learn
Collecting scikit-learnUsing cached scikit_learn-0.19.1-cp36-cp36m-win_amd64.whlInstalling collected packages: scikit-learn
Successfully installed scikit-learn-0.19.1

其他安装方式,使用pip安装:

pip3 install -U scikit-learn#针对python3以上版本

3、测试是否成功

C:\Users\RoFun>python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.
1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.#测试numpy
>>> from numpy import *
>>> random.rand(4,4)
array([[ 0.50577718,  0.28084544,  0.60065843,  0.13602574],[ 0.21017214,  0.95728551,  0.86767926,  0.28480014],[ 0.09599413,  0.1180833 ,  0.32564685,  0.86346346],[ 0.44717601,  0.48939418,  0.66523856,  0.59264163]])#测试SciPy
>>> mamat=mat(random.rand(4,4))
>>> mamat.I
matrix([[-0.21932642, -0.21289052,  3.39586459, -0.97625391],[-1.24711187,  2.321002  , -4.25158411,  3.64620557],[ 3.42909455, -5.57118063,  1.78018854,  0.39327149],[-0.63002829,  3.00212206, -2.29609706, -0.79183222]])

测试sk-learn

>>> import scikit
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ImportError: No module named 'scikit'>>> from sklearn import datasets
>>> digits=datasets.load_digits()
>>> print(digits.data)
[[  0.   0.   5. ...,   0.   0.   0.][  0.   0.   0. ...,  10.   0.   0.][  0.   0.   0. ...,  16.   9.   0.]...,[  0.   0.   1. ...,   6.   0.   0.][  0.   0.   2. ...,  12.   0.   0.][  0.   0.  10. ...,  12.   1.   0.]]

参考:

  1. sk-learn入门教程
  相关解决方案