如何在没有类型错误的情况下在 python 3.5.0 上导入 sklearn?

Posted

技术标签:

【中文标题】如何在没有类型错误的情况下在 python 3.5.0 上导入 sklearn?【英文标题】:How do I import sklearn on python 3.5.0 without a Type error? 【发布时间】:2020-11-05 02:05:39 【问题描述】:

我通过此页面安装了安装 sklearn 的先决条件:https://scikit-learn.org/stable/install.html 并且一切安装正常。但是,当我尝试导入 sklearn 时,我收到错误(如下)。有什么想法吗?

安装:

# pip3 install -U scikit-learn[alldeps]==0.22
Looking in indexes: http://devpi.na-pytools.tds.local/na/dev/+simple/
Requirement already up-to-date: scikit-learn[alldeps]==0.22 in /usr/local/lib/python3.5/site-packages (0.22)
Requirement already satisfied, skipping upgrade: scipy>=0.17.0 in /usr/local/lib/python3.5/site-packages (from scikit-learn[alldeps]==0.22) (1.4.1)
Requirement already satisfied, skipping upgrade: joblib>=0.11 in /usr/local/lib/python3.5/site-packages (from scikit-learn[alldeps]==0.22) (0.14.0)
Requirement already satisfied, skipping upgrade: numpy>=1.11.0 in /usr/local/lib/python3.5/site-packages (from scikit-learn[alldeps]==0.22) (1.18.1)

错误:

Python 3.5.0 (default, Nov 19 2015, 10:11:12)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/sklearn/__init__.py", line 74, in <module>
    from .base import clone
  File "/usr/local/lib/python3.5/site-packages/sklearn/base.py", line 20, in <module>
    from .utils import _IS_32BIT
  File "/usr/local/lib/python3.5/site-packages/sklearn/utils/__init__.py", line 18, in <module>
    from scipy.sparse import issparse
  File "/usr/local/lib/python3.5/site-packages/scipy/__init__.py", line 156, in <module>
    from . import fft
  File "/usr/local/lib/python3.5/site-packages/scipy/fft/__init__.py", line 76, in <module>
    from ._basic import (
  File "/usr/local/lib/python3.5/site-packages/scipy/fft/_basic.py", line 1, in <module>
    from scipy._lib.uarray import generate_multimethod, Dispatchable
  File "/usr/local/lib/python3.5/site-packages/scipy/_lib/uarray.py", line 27, in <module>
    from ._uarray import *
  File "/usr/local/lib/python3.5/site-packages/scipy/_lib/_uarray/__init__.py", line 114, in <module>
    from ._backend import *
  File "/usr/local/lib/python3.5/site-packages/scipy/_lib/_uarray/_backend.py", line 1, in <module>
    from typing import (
ImportError: cannot import name 'Type'

【问题讨论】:

【参考方案1】:

我最终用 make altinstall 和 virtualenv 安装了 python 3.6.8,解决了这个问题。

【讨论】:

以上是关于如何在没有类型错误的情况下在 python 3.5.0 上导入 sklearn?的主要内容,如果未能解决你的问题,请参考以下文章

在没有模型的情况下在 MVC 中引发验证错误

如何使用 Python 在没有窗口的情况下在屏幕上显示文本

如何在没有浏览器的情况下在 python 中使用 Tor?

如何在没有来自脚本的 Internet 连接的情况下在 Python 中转发地理编码?

如何在没有任何视图或任何其他表类型的情况下在 oracle 中创建具有动态列名和动态数据类型的动态表

如何在没有 FBConfig 错误的情况下在 docker 内运行 glut 应用程序?