ModuleNotFoundError: No module named ‘sklearn.neural_network.multilayer_perceptron‘

省流:换python3.8及以下

查到有的资料[1]说

pip install scikit-learn==0.22.2.post1

于是

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 303, in <module>
          setup_package()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 299, in setup_package
          setup(**metadata)
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
          config = configuration()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 180, in configuration
          _check_cython_version()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\sklearn\_build_utils\__init__.py", line 35, in _check_cython_version
          raise ModuleNotFoundError(message)
      ModuleNotFoundError: Please install Cython with a version >= 0.28.5 in order to build a scikit-learn from source.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scikit-learn
  Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects

可以都看到,没有Cython >= 0.28.5,因此

pip install Cython
INFO: No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 303, in <module>
          setup_package()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 299, in setup_package
          setup(**metadata)
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
          config = configuration()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 182, in configuration
          config.add_subpackage('sklearn')
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1050, in add_subpackage
          config_list = self.get_subpackage(subpackage_name, subpackage_path,
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1016, in get_subpackage
          config = self._get_configuration_from_setup_py(
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 958, in _get_configuration_from_setup_py
          config = setup_module.configuration(*args)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\setup.py", line 86, in configuration
          cythonize_extensions(top_path, config)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\__init__.py", line 50, in cythonize_extensions
          basic_check_build()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\pre_build_helpers.py", line 70, in basic_check_build
          compile_test_program(code)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\pre_build_helpers.py", line 39, in compile_test_program
          ccompiler.compile(['test_program.c'], output_dir='objects',
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 343, in compile
          self.initialize()
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 253, in initialize
          vc_env = _get_vc_env(plat_spec)
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\msvc.py", line 233, in msvc14_get_vc_env
          return _msvc14_get_vc_env(plat_spec)
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\msvc.py", line 190, in _msvc14_get_vc_env
          raise distutils.errors.DistutilsPlatformError("Unable to find vcvarsall.bat")
      distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scikit-learn
  Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects

进入这里
https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/
在这里插入图片描述
打开cmd[2]

vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools

会跳出来这个
在这里插入图片描述

The above exception was the direct cause of the following exception:
     
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 303, in <module>
          setup_package()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 299, in setup_package
          setup(**metadata)
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
          config = configuration()
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 182, in configuration
          config.add_subpackage('sklearn')
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1050, in add_subpackage
          config_list = self.get_subpackage(subpackage_name, subpackage_path,
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1016, in get_subpackage
          config = self._get_configuration_from_setup_py(
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 958, in _get_configuration_from_setup_py
          config = setup_module.configuration(*args)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\sklearn\setup.py", line 86, in configuration
          cythonize_extensions(top_path, config)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\sklearn\_build_utils\__init__.py", line 75, in cythonize_extensions
          config.ext_modules = cythonize(
        File "D:\miniconda3\envs\moba_ai\lib\site-packages\Cython\Build\Dependencies.py", line 1145, in cythonize
          result.get(99999)  # seconds
        File "D:\miniconda3\envs\moba_ai\lib\multiprocessing\pool.py", line 771, in get
          raise self._value
      Cython.Compiler.Errors.CompileError: sklearn\svm\_liblinear.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scikit-learn
  Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects

nmdwsm
经过一些玄学尝试,最后发现,似乎和版本有问题
python3.6.10,和python3.8.10是可以的(目测3.7也可以)
python3.9.0和python3.10.0不行
创建环境

conda create n test1 python==3.8.10

安装

pip install numpy cython
pip install scikit-learn==0.22.2.post1

终于可以了

参考:
[1] https://stackoverflow.com/questions/61177448/no-module-named-sklearn-neural-network-multilayer-perceptron
[2] https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nightmare004

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值