代码之家  ›  专栏  ›  技术社区  ›  Chandima Maduwantha

使用pip安装scikit learn时出错:准备元数据(pyproject.toml)未成功运行

  •  -1
  • Chandima Maduwantha  · 技术社区  · 1 年前

    我试图为django项目安装scikit-learn==1.2.2,但我得到了这个错误。

     Collecting scikit-learn==1.2.2
      Using cached scikit-learn-1.2.2.tar.gz (7.3 MB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... error
      error: subprocess-exited-with-error
    
      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [36 lines of output]
          Partial import of sklearn during the build process.
          Traceback (most recent call last):
            File "D:\Group Project Backend\Prediction\env\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
              main()
            File "D:\Group Project Backend\Prediction\env\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
              json_out['return_val'] = hook(**hook_input['kwargs'])
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "D:\Group Project Backend\Prediction\env\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 149, in prepare_metadata_for_build_wheel
              return hook(metadata_directory, config_settings)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\build_meta.py", line 366, in prepare_metadata_for_build_wheel
              self.run_setup()
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\build_meta.py", line 487, in run_setup
              super().run_setup(setup_script=setup_script)
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
              exec(code, locals())
            File "<string>", line 669, in <module>
            File "<string>", line 663, in setup_package
            File "<string>", line 597, in configure_extension_modules
            File "C:\Users\ASUS\AppData\Local\Temp\pip-install-xv622fd3\scikit-learn_6df30b226b524d1caf236a6b94005795\sklearn\_build_utils\__init__.py", line 47, in cythonize_extensions
              basic_check_build()
            File "C:\Users\ASUS\AppData\Local\Temp\pip-install-xv622fd3\scikit-learn_6df30b226b524d1caf236a6b94005795\sklearn\_build_utils\pre_build_helpers.py", line 82, in basic_check_build
              compile_test_program(code)
            File "C:\Users\ASUS\AppData\Local\Temp\pip-install-xv622fd3\scikit-learn_6df30b226b524d1caf236a6b94005795\sklearn\_build_utils\pre_build_helpers.py", line 38, in compile_test_program
              ccompiler.compile(
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 343, in compile
              self.initialize()
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 253, in initialize
              vc_env = _get_vc_env(plat_spec)
                       ^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\msvc.py", line 230, in msvc14_get_vc_env
              return _msvc14_get_vc_env(plat_spec)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\ASUS\AppData\Local\Temp\pip-build-env-_ej3exwe\overlay\Lib\site-packages\setuptools\msvc.py", line 187, 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: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.
    

    `

    我在我的windows机器中使用pyhton 3.12.2。我正在使用React和django建立职业预测网站。我使用vscode作为IDE。我使用谷歌拼贴画训练了一个模型,它被用于scikit learn的1.2.2版本。我可以安装Django、djangorestframework等其他软件包,但不能安装scikit-learn。 我正在虚拟环境中安装所有东西。

    2 回复  |  直到 1 年前
        1
  •  0
  •   Thari_DB01    1 年前

    您遇到此问题的原因是,从源代码构建scikit学习包需要Microsoft Visual C++14.0或更高版本。安装所需的构建工具是解决此问题的第一步。以下是操作方法:

    1. 安装Microsoft C++生成工具: link

    2. 更新pip和setuptool。

      pip-install—升级pipsetuptools

    3. 安装scikit learn

      pip安装scikit学习==1.2.2

        2
  •  0
  •   phd    1 年前

    为Python 3.12提供轮子的第一个版本是scikit learn 1.4.0。看见 https://pypi.org/project/scikit-learn/1.4.0/#files 。所以不要使用旧版本,使用新版本。任何一个 pip install scikit-learn==1.4.2 或者简单地 pip install scikit-learn 最新的一个(目前为1.5)。

    版本1.2.2 provides wheels 直到Python 3.11。如果要使用1.2.2,请使用较旧的Python。降级到Python 3.11。