今天运行一个python机器学习项目,结果报错连连,出现两个问题:
觉得很有意义,这里记录一下。
一个老项目要求sklearn版本是0.23.1的,我卸载当前版本,安装该版本时,报错如下:
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: scikit-learn
Running setup.py install for scikit-learn ... error
ERROR: Command errored out with exit status 1:
command: 'd:\python3.8.6\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ShuoZhou\\AppData\\Local\\Temp\\pip-install-i2fx2kkz\\scikit-learn_720f98e63aee466680093cc0442276ca\\setup.py'"'"'; __file__='"'"'C:\\Users\\ShuoZhou\\AppData\\Local\\Temp\\pip-install-i2fx2kkz\\scikit-learn_720f98e63aee466680093cc0442276ca\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ShuoZhou\AppData\Local\Temp\pip-record-cmmjlg7n\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\python3.8.6\Include\scikit-learn'
cwd: C:\Users\ShuoZhou\AppData\Local\Temp\pip-install-i2fx2kkz\scikit-learn_720f98e63aee466680093cc0442276ca\
Complete output (28 lines):
Partial import of sklearn during the build process.
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ShuoZhou\AppData\Local\Temp\pip-install-i2fx2kkz\scikit-learn_720f98e63aee466680093cc0442276ca\setup.py", line 290, in
setup_package()
File "C:\Users\ShuoZhou\AppData\Local\Temp\pip-install-i2fx2kkz\scikit-learn_720f98e63aee466680093cc0442276ca\setup.py", line 286, in setup_package
setup(**metadata)
File "d:\python3.8.6\lib\site-packages\numpy\distutils\core.py", line 135, in setup
config = configuration()
File "C:\Users\ShuoZhou\AppData\Local\Temp\pip-install-i2fx2kkz\scikit-learn_720f98e63aee466680093cc0442276ca\setup.py", line 174, in configuration
config.add_subpackage('sklearn')
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 1018, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 984, in get_subpackage
config = self._get_configuration_from_setup_py(
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 926, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "sklearn\setup.py", line 62, in configuration
config.add_subpackage('utils')
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 1018, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 984, in get_subpackage
config = self._get_configuration_from_setup_py(
File "d:\python3.8.6\lib\site-packages\numpy\distutils\misc_util.py", line 926, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "sklearn\utils\setup.py", line 8, in configuration
from Cython import Tempita
ModuleNotFoundError: No module named 'Cython'
----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\python3.8.6\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ShuoZhou\\AppData\\Local\\Temp\\pip-install-i2fx2kkz\\scikit-learn_720f98e63aee466680093cc0442276ca\\setup.py'"'"'; __file__='"'"'C:\\Users\\ShuoZhou\\AppData\\Local\\Temp\\pip-install-i2fx2kkz\\scikit-learn_720f98e63aee466680093cc0442276ca\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ShuoZhou\AppData\Local\Temp\pip-record-cmmjlg7n\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\python3.8.6\Include\scikit-learn' Check the logs for full command output.
查询资料找到一种方法:在下方网站上下载对应的python库的wheel(.whl)文件,然后pip install .whl文件的绝对路径,或者cd到,whl文件的路径,然后pip install .whl文件,下载地址:
下载完成后,使用如下命令进行安装:
pip install .whl文件的绝对路径
结果报错:
ERROR: scikit_learn-0.23.1-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
该错误表示你要下载的依赖库版本与你的python版本不一致,日,搞了半天还是不行。
差点就要替换python版本了,后来发现了一种新的方法,直接替换.whl文件的名称,居然就可以行的通。.whl文件前后变化:
//初始名称
scikit_learn-0.23.1-cp36-cp36m-win_amd64.whl
//变化之后
scikit_learn-0.23.1-cp38-none-any.whl
将.whl文件重命名之后,居然顺利安装成功了,而且版本不变,就是0.23.1,神奇!
需要注意的是,我一开始按照网上资料重命名为scikit_learn-0.23.1-cp36-none-any.whl,发现还是不行,后来想到自己的python版本是3.8,于是将cp36更改为了cp38,没想到还真成了,如果你的版本不是3.8,而是3.x,建议更改为cp3x。