首页 > 解决方案 > 尝试将 sklearn 数据集导入 Jupyter Notebook 时出现 OSError

问题描述

使用以下代码:

from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
housing

我得到错误:

    OSError                                   Traceback (most recent call last)
<ipython-input-19-b7c74cbf5af0> in <module>
----> 1 import sklearn

~\AppData\Roaming\Python\Python38\site-packages\sklearn\__init__.py in <module>
     78     # later is linked to the OpenMP runtime to make it possible to introspect
     79     # it and importing it first would fail if the OpenMP dll cannot be found.
---> 80     from . import _distributor_init  # noqa: F401
     81     from . import __check_build  # noqa: F401
     82     from .base import clone

~\AppData\Roaming\Python\Python38\site-packages\sklearn\_distributor_init.py in <module>
     20     vcomp140_dll_filename = op.join(libs_path, "vcomp140.dll")
     21     vcruntime140_dll_filename = op.join(libs_path, "vcruntime140.dll")
---> 22     WinDLL(op.abspath(vcomp140_dll_filename))
     23     WinDLL(op.abspath(vcruntime140_dll_filename))

~\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    371 
    372         if handle is None:
--> 373             self._handle = _dlopen(self._name, mode)
    374         else:
    375             self._handle = handle

OSError: [WinError 193] %1 is not a valid Win32 application

在我的机器上我安装了 Python 32 和 64 位,所以我假设问题是我运行代码的 Jupyter Lab 与我机器上的 python 版本和 sklearn 使用的版本不匹配,导致问题?

在此之前,我对 sklearn 或使用 Jupyter Notebook 进行分析没有任何问题。

我使用的是 Windows,如何正确读取 sklearn Real life 数据集?

标签: pythonwindowsscikit-learnjupyter-notebook

解决方案


我现在已经解决了这个问题。我安装了两个版本的 Python,一个在我的 Anaconda 路径中,一个直接下载到我的机器上。机器版本是 32 位,Anaconda 是 64 位,所以我删除了 32 位版本,因为我的电脑是 64 位,而且我使用的是 Anaconda 环境。


推荐阅读