繁体   English   中英

在 jupyter notebook 中导入 sklearn 时出现操作系统错误

[英]OS error while importing sklearn in jupyter notebook

import sklearn

我收到此错误:

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

~\AppData\Roaming\Python\Python37\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\Python37\site-packages\sklearn\_distributor_init.py in <module>
     16     # Pre-load the DLL stored in sklearn/.libs by convention.
     17     dll_path = op.join(op.dirname(__file__), '.libs', 'vcomp140.dll')
---> 18     WinDLL(op.abspath(dll_path))
     19 

~\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    354 
    355         if handle is None:
--> 356             self._handle = _dlopen(self._name, mode)
    357         else:
    358             self._handle = handle

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

请在这件事上给予我帮助

使用环境,因为你有 conda 作为你的 package 经理。 请执行下列操作:

  1. 使用所需的包创建环境
  2. 激活并在该环境中工作

代码:

# create and activate env called ml with Python 3.7 and jupyter lab and scikit-learn 
conda create -n ml python=3.7 scikit-learn jupyterlab
conda activate ml

# check that all is fine by print scikit-learn version
python -c "import sklearn;print(sklearn.__version__)"

# if no error, spin jupyter Lab
jupyter lab 

您可以在命令行上将更多包添加到您的环境中:

conda install -n ml pandas requests

如果要安装 pip 软件包。 您必须先激活正确的环境。

conda activate ml
python -m pip install geopy 

停用conda deactivate

创建项目特定环境是一种很好的做法。 仅安装使用过的软件包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM