运行python程序时,遇到了问题:
ImportError: No module named sklearn.cluster
本以为就简单的安装个包就可以,执行如下:
pip install scikit-learn
结果却出错:
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.python.org/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd04127240>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/scikit-learn/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd04127cc0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/scikit-learn/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd041270f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/scikit-learn/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd04127c50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/scikit-learn/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd04127da0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/scikit-learn/
ERROR: Could not find a version that satisfies the requirement scikit-learn (from versions: none)
ERROR: No matching distribution found for scikit-learn
根据https://blog.csdn.net/aiqinchao/article/details/89522180的提示换了国内源也不行
此时有点懵逼,从来没出现过这个问题,遂尝试用apt-get安装:
sudo apt-get install python-sklearn
结果也报错,提示apt-get升级一下,我又执行 sudo apt-get update,结果还是不行:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
python-joblib python-simplejson python-sklearn-lib
Suggested packages:
python-dap python-scikits-optimization python-sklearn-doc ipython
The following NEW packages will be installed:
python-joblib python-simplejson python-sklearn python-sklearn-lib
0 upgraded, 4 newly installed, 0 to remove and 90 not upgraded.
Need to get 2,368 kB of archives.
After this operation, 11.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:1 http://mirrors.aliyun.com/ubuntu xenial/universe i386 python-joblib all 0.9.4-1
Err:2 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python-simplejson amd64 3.8.1-1ubuntu2
Temporary failure resolving 'mirrors.aliyun.com'
Ign:3 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 python-sklearn-lib amd64 0.17.0-4
Ign:4 http://mirrors.aliyun.com/ubuntu xenial/universe i386 python-sklearn all 0.17.0-4
Err:2 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python-simplejson amd64 3.8.1-1ubuntu2
Temporary failure resolving 'mirrors.aliyun.com'
Err:3 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 python-sklearn-lib amd64 0.17.0-4
Temporary failure resolving 'mirrors.aliyun.com'
Err:1 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 python-joblib all 0.9.4-1
Temporary failure resolving 'mirrors.aliyun.com'
Err:1 http://cn.archive.ubuntu.com/ubuntu xenial/universe i386 python-joblib all 0.9.4-1
Temporary failure resolving 'mirrors.aliyun.com'
Ign:4 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 python-sklearn all 0.17.0-4
Err:1 http://cn.archive.ubuntu.com/ubuntu xenial/universe i386 python-joblib all 0.9.4-1
Temporary failure resolving 'mirrors.aliyun.com'
Err:4 http://cn.archive.ubuntu.com/ubuntu xenial/universe i386 python-sklearn all 0.17.0-4
Temporary failure resolving 'mirrors.aliyun.com'
Err:4 http://cn.archive.ubuntu.com/ubuntu xenial/universe i386 python-sklearn all 0.17.0-4
Temporary failure resolving 'mirrors.aliyun.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/j/joblib/python-joblib_0.9.4-1_all.deb Temporary failure resolving 'mirrors.aliyun.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/s/simplejson/python-simplejson_3.8.1-1ubuntu2_amd64.deb Temporary failure resolving 'mirrors.aliyun.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/s/scikit-learn/python-sklearn-lib_0.17.0-4_amd64.deb Temporary failure resolving 'mirrors.aliyun.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/s/scikit-learn/python-sklearn_0.17.0-4_all.deb Temporary failure resolving 'mirrors.aliyun.com'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
就在无可奈何的时候找到一篇博客https://blog.csdn.net/aiqinchao/article/details/89522180,说是DNS出现了问题,我没有动过网络DNS怎么会有问题,本着死马当活马医的态度,修改了DNS,结果令我惊喜,一切又恢复了原样,pip install xxx,apt-get update 统统ok,在这谢谢博主,以下是修改方法:
1. 打开’/etc/network/interfaces’文件,没有则创建一个,添加
dns-nameservers 223.5.5.5 223.6.6.6
2. 打开’/etc/resolv.conf’文件并添加两行’
nameserver 223..5.5.5
nameserver 223.6.6.6