from sklearn.externals import joblib ImportError: cannot import name 'joblib' from 'sklearn.externals' (/home/aaa/anaconda3/lib/python3.9/site-packages/sklearn/externals/__init__.py)
时间: 2023-08-03 18:08:54 浏览: 59
这个错误是因为在最新版本的 scikit-learn 中,`joblib` 被移动到了一个单独的包中,你需要安装 `joblib` 包才能使用它。你可以通过运行以下命令来安装它:
```
pip install joblib
```
如果你使用的是 scikit-learn 0.23 版本及以上的版本,可以直接使用以下代码来导入 `joblib`:
```
from sklearn import set_config
set_config(working_memory=True)
```
这将启用 scikit-learn 的内置缓存机制,以便更有效地使用内存。
相关问题
ImportError: cannot import name 'joblib' from 'sklearn.externals' (e:\mlp\anaconda3\lib\site-packages\sklearn\externals\__init__.py)
The error message suggests that you are trying to import the `joblib` module from the `sklearn.externals` package, but it is not found in that package.
In newer versions of scikit-learn (v0.21 and above), `joblib` has been moved to a standalone package and is no longer included in `sklearn.externals`. To fix this error, you should import `joblib` from its new location:
```python
from joblib import dump, load
```
You can then use the `dump` and `load` functions to save and load your machine learning models.
If you are using an older version of scikit-learn and cannot upgrade, you can try importing `joblib` from its old location:
```python
from sklearn.externals import joblib
```
However, this is not recommended as the `sklearn.externals` module has been removed in scikit-learn v0.23 and above, and `joblib` should always be imported from its standalone package.
ImportError: cannot import name 'joblib' from 'sklearn.externals' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\__init__.py)
根据提供的引用内容,出现ImportError: cannot import name 'joblib' from 'sklearn.externals' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\__init__.py) 错误是因为在sklearn库的最新版本中移除了joblib函数或包。解决这个问题的方法是直接下载和安装joblib包。你可以按照以下步骤进行操作:
1. 打开终端或命令提示符。
2. 输入以下命令来安装joblib包:pip install joblib
3. 等待安装完成后,再次尝试import joblib,应该就可以成功导入了。
请注意,确保你的pip工具是最新版本,可以通过运行以下命令来升级pip:pip install --upgrade pip
希望这个解决方法对你有所帮助。如果还有其他问题,请随时告诉我。