gpt4 book ai didi

scikit-learn - Jupyter 笔记本导入错误 : No module named 'sklearn'

转载 作者:行者123 更新时间:2023-12-03 09:29:30 24 4
gpt4 key购买 nike

我正在尝试在我的本地机器上运行。我收到一个错误
ImportError:仅在 jupyter 笔记本中没有名为“sklearn”的模块
当我从命令行使用 python 并激活和停用 carnd-term1 env 时,它工作正常。

我已经用 pip、apt-get 和 conda 安装了 sklearn。还尝试了 conda upgrade scikit-learn。 env 处于事件状态和停用状态。

(carnd-term1) matt@Malta:~/sdc$ conda upgrade scikit-learn
Fetching package metadata .........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /home/matt/anaconda3/envs/carnd-term1:
#
scikit-learn 0.18.1 np112py35_1
(carnd-term1) matt@Malta:~/sdc$ python3
Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
>>>
   ...: (carnd-term1) matt@Malta:~/sdc$ ipython
...: Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33)
...: Type "copyright", "credits" or "license" for more information.
...:
...: IPython 5.1.0 -- An enhanced Interactive Python.
...: ? -> Introduction and overview of IPython's features.
...: %quickref -> Quick reference.
...: help -> Python's own help system.
...: object? -> Details about 'object', use 'object??' for extra details.
...:
...: In [1]: import sklearn
...:
...: In [2]: from sklearn.model_selection import train_test_split
...:
...: In [3]: (carnd-term1) matt@Malta:~/sdc$ ipython
...: ...: Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33)
...: ...: Type "copyright", "credits" or "license" for more information.
...: ...:
...: ...: IPython 5.1.0 -- An enhanced Interactive Python.
...: ...: ? -> Introduction and overview of IPython's features.
...: ...: %quickref -> Quick reference.
...: ...: help -> Python's own help system.
...: ...: object? -> Details about 'object', use 'object??' for extra details.
...: ...:
...: ...: In [1]: import sklearn
...: ...:
...: ...: In [2]: from sklearn.model_selection import train_test_split
...: ...:
...: ...: In [3]:

不适用于 jupyter 笔记本。

有任何想法吗?

最佳答案

这一般意味着两者不是同一个环境。最好检查一下 sys.executable并确保这是您所期望的。如果是笔记本没有使用 sys.executable您期望,第一步可能是检查您的路径:

which jupyter
which jupyter-notebook

最可能的问题是笔记本堆栈不在您的 conda 环境中,您可以通过以下方式解决:
conda install notebook

第二个最有可能的是您安装了覆盖您的环境的内核规范(例如,使用 ipython kernel install --user )。你可以看到你的内核在哪里:
jupyter kernelspec list

为确保您在同一环境中安装了 IPython 内核,您可以执行以下操作:
conda install ipykernel
ipython kernelspec install --sys-prefix

并检查 jupyter kernelspec list之后再次。

关于scikit-learn - Jupyter 笔记本导入错误 : No module named 'sklearn' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42178070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com