Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误

错误

在Jupyter Notebook中使用SMOTE算法时,输入from imblearn.over_sampling import SMOTE出现了错误:“ModuleNotFoundError: No module named ‘imblearn’”。

Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误_第1张图片

探索解决方法

在安装的过程中走了许多弯路:
首先我看到有文章中的解决方法是,在cmd命令中输入:pip install imbalanced-learn,然后按回车键。
Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误_第2张图片
输入pip install imbalanced-learn后可能会出现新的错误:“Could not fetch URL https://pypi.org/simple/imbalanced-learn/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘pypi.org’, port=443): Max retries exceeded with url: /simple/imbalanced-learn/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) - skipping
Could not find a version that satisfies the requirement imbalanced-learn (from versions: )
No matching distribution found for imbalanced-learn”

我们可以使用国内镜像网站下载直接安装,输入“pip install imbalanced-learn -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com”,记得后面“ --trusted-host pypi.douban.com”一定不能少,否则会出现下图错误:
在这里插入图片描述
看到下图说明开始进行安装啦:
Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误_第3张图片
结果又出现了新的错误:“Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: ‘C:\Users\HUANGY~1\AppData\Local\Temp\pip-uninstall-gyg_sqj2\users\huangyanli\anaconda3\lib\site-packages\sklearn\ensemble\_gradient_boosting.cp37-win_amd64.pyd’
Consider using the --user option or check the permissions.”

Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误_第4张图片
因此还要加一个“–user”,改为“pip install --user imbalanced-learn -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com”。
Jupyter Notebook中出现“ModuleNotFoundError: No module named 'imblearn'”错误_第5张图片
这次终于安装成功!

你可能感兴趣的:(Python各种错误)