首页 > 编程问答 >安装 scikit 从 pip 学习时出错

安装 scikit 从 pip 学习时出错

时间:2024-07-30 06:29:16浏览次数:17  
标签:python installation scikit-learn pip subprocess

我一直在尝试通过命令安装 scikit learn pip install scikit-learn ,但它向我显示了下面给出的错误。

PS:

  • Python 版本 3.8.5
  • pip 版本 22.3

错误显示:

Collecting scikit-learn
  Using cached scikit-learn-1.1.3.tar.gz (7.0 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [96 lines of output]

 Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Windows" and platform_python_implementation != "PyPy"' don't match your environment
      Collecting setuptools<60.0
        Using cached setuptools-59.8.0-py3-none-any.whl (952 kB)
      Collecting wheel
        Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
      Collecting Cython>=0.28.5
        Using cached Cython-0.29.32-py2.py3-none-any.whl (986 kB)
      Collecting oldest-supported-numpy
        Using cached oldest_supported_numpy-2022.8.16-py3-none-any.whl (3.9 kB)
      Collecting scipy>=1.3.2
        Using cached scipy-1.9.3.tar.gz (42.1 MB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'error'
        error: subprocess-exited-with-error

        Getting requirements to build wheel did not run successfully.
        exit code: 1

        [64 lines of output]
        The Meson build system
        Version: 0.63.3
        Source dir: C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67
        Build dir: C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build
        Build type: native build
        Project name: SciPy
        Project version: 1.9.3
        C compiler for the host machine: gcc (gcc 9.2.0 "gcc (MinGW.org GCC Build-2) 9.2.0")
        C linker for the host machine: gcc ld.bfd 2.32
        C++ compiler for the host machine: c++ (gcc 9.2.0 "c++ (MinGW.org GCC Build-2) 9.2.0")
        C++ linker for the host machine: c++ ld.bfd 2.32
        Host machine cpu family: x86
        Host machine cpu: x86
        Compiler for C supports arguments -Wno-unused-but-set-variable: YES
        Compiler for C supports arguments -Wno-unused-but-set-variable: YES (cached)
        Compiler for C supports arguments -Wno-unused-function: YES
        Compiler for C supports arguments -Wno-conversion: YES
        Compiler for C supports arguments -Wno-misleading-indentation: YES
        Compiler for C supports arguments -Wno-incompatible-pointer-types: YES
        Library m found: YES

        ..\..\meson.build:57:0: ERROR: Unknown compiler(s): [['ifort'], ['gfortran'], ['flang'], ['pgfortran'], ['g95']]
        The following exception(s) were encountered:
        Running `ifort --version` gave "[WinError 2] The system cannot find the file specified"
        Running `ifort -V` gave "[WinError 2] The system cannot find the file specified"
        Running `gfortran --version` gave "[WinError 2] The system cannot find the file specified"
        Running `gfortran -V` gave "[WinError 2] The system cannot find the file specified"
        Running `flang --version` gave "[WinError 2] The system cannot find the file specified"
        Running `flang -V` gave "[WinError 2] The system cannot find the file specified"
        Running `pgfortran --version` gave "[WinError 2] The system cannot find the file specified"
        Running `pgfortran -V` gave "[WinError 2] The system cannot find the file specified"
        Running `g95 --version` gave "[WinError 2] The system cannot find the file specified"
        Running `g95 -V` gave "[WinError 2] The system cannot find the file specified"

        A full log can be found at C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build\meson-logs\meson-log.txt
        + meson setup --native-file=C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-native-file.ini -Ddebug=false -Doptimization=2 --prefix=c:\users\manju\appdata\local\programs\python\python38-32 C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67 C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build
        Traceback (most recent call last):
          File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 351, in <module>
            main()
          File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 118, in get_requires_for_build_wheel
            return hook(config_settings)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 969, in get_requires_for_build_wheel
            with _project(config_settings) as project:
          File "c:\users\manju\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__
            return next(self.gen)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 948, in _project
            with Project.with_temp_working_dir(
          File "c:\users\manju\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__
            return next(self.gen)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 777, in with_temp_working_dir
            yield cls(source_dir, tmpdir, build_dir)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 682, in __init__
            self._configure(reconfigure=bool(build_dir) and not native_file_mismatch)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 713, in _configure
            self._meson(
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 696, in _meson
            return self._proc('meson', *args)
          File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 691, in _proc
            subprocess.check_call(list(args))
          File "c:\users\manju\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
            raise CalledProcessError(retcode, cmd)
        subprocess.CalledProcessError: Command '['meson', 'setup', '--native-file=C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67\\.mesonpy-native-file.ini', '-Ddebug=false', '-Doptimization=2', '--prefix=c:\\users\\manju\\appdata\\local\\programs\\python\\python38-32', 'C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67', 'C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67\\.mesonpy-nddxhmy3\\build']' returned non-zero exit status 1.
        [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: subprocess-exited-with-error

      Getting requirements to build wheel did not run successfully.
      exit code: 1

      See above for output.

      note: This error originates from a subprocess, and is likely not a problem with pip.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

安装 scikit-learn 时出现的错误与缺少 SciPy(安装 scikit-learn 的依赖项)构建轮子所需的 Fortran 编译器有关。

以下是解决此问题的方法:

1. 安装 Fortran 编译器:

  • 对于 Windows:
  • 最简单的方法是安装 MinGW-w64。你可以从 https://www.mingw-w64.org/ 下载。在安装过程中,请确保选择了正确的架构(32 位或 64 位),并包含了 Fortran 编译器(例如 gfortran)。
  • 对于 macOS:
  • 你可以使用 Homebrew 安装 gfortran: brew install gcc
  • 对于 Linux:
  • 使用你的发行版的包管理器安装 gfortran。例如,在 Ubuntu/Debian 上: sudo apt-get install gfortran

2. 将 Fortran 编译器添加到你的 PATH 环境变量:

  • 确保 Fortran 编译器(例如 gfortran.exe)所在的目录在你的 PATH 环境变量中。这将允许 pip 找到编译器。

3. 升级 pip:

  • 在某些情况下,过时的 pip 版本可能会导致问题。尝试升级 pip: pip install --upgrade pip

4. 重新安装 scikit-learn:

  • 完成上述步骤后,再次尝试安装 scikit-learn: pip install scikit-learn

如果问题仍然存在,请尝试以下操作:

  • 创建一个新的虚拟环境: 虚拟环境可以帮助你避免软件包之间的冲突。
  • 使用预编译的轮子: 考虑从 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载 SciPy 的预编译轮子,并使用 pip 手动安装。
  • 升级 setuptools: 确保 setuptools 是最新的: pip install --upgrade setuptools

这些步骤应该可以帮助你成功安装 scikit-learn。如果问题仍然存在,请提供你的操作系统以及有关你环境的更多信息,以便我提供更具体的帮助。

标签:python,installation,scikit-learn,pip,subprocess
From: 74226688

相关文章

  • 使用 DQN 实现 pong,使用 python 中的特征向量而不是像素。我的 DQNA 实现代码正确吗,因
    我正在致力于使用OpenAI的Gym为Pong游戏实现强化学习(RL)环境。目标是训练人工智能代理通过控制球拍来打乒乓球。代理收到太多负面奖励,即使它看起来移动正确。具体来说,奖励函数会惩罚远离球的智能体,但这种情况发生得太频繁,即使球朝球拍移动时似乎也会发生。观察......
  • Python CDLL 无法加载两次
    我正在尝试用python创建一个密码管理器,但遇到了一个问题,一旦加载了一种类型的dll,我就无法加载不同的dll,在这个示例中,我加载了一个dll,并尝试解密加密的密码数据,它工作正常,直到我加载另一个不同的nss3.dll文件,此时它给我一个错误:“过程入口点HeapAlloc无法位于动态链......
  • 你能将 HTTPS 功能添加到 python Flask Web 服务器吗?
    我正在尝试构建一个Web界面来模拟网络设备上的静态接口,该网络设备使用摘要式身份验证和HTTPS。我想出了如何将摘要式身份验证集成到Web服务器中,但我似乎无法找到如何使用FLASK获取https,如果您可以向我展示如何实现,请评论我需要使用下面的代码做什么来实现这一点。from......
  • Python:比较 csv 文件并打印相似之处
    我需要比较两个csv文件并打印出它们的相似之处。第一个文件有名称和浓度,第二个文件就像只有名称的“最佳”列表,我需要绘制相似性图表。例如,这就是我的列表的样子:file1-old_file.csvname_id,conc_test1,conc_test2name1,####,####name2,###......
  • Python 类交叉引用
    我用Python创建了一个数独游戏。我有一个:单元格类-“保存”数字可能性单元格组-保存单元格类实例我使用这些组在数独中运行行、列和正方形功能。每个单元格包含所有组,他属于classCell:def__init__(groups):self.groups=groupscla......
  • 如何修复我的 Python Azure Function DevOps Pipeline 上的“找到 1 个函数(自定义)加载
    我正在尝试使用AzureDevOps构建管道将PythonAzureFunction部署到Azure门户。由于某种原因,代码被部署到服务器,但我在尝试访问端点时收到404错误。我收到一个错误,显示1functionsfound(Custom)0functionsloaded,以及在服务器上显示ModuleNotFound......
  • 使用 kivy 从 python 脚本的 buildozer 构建 android apk 时出错
    我想从使用kivy包构建的Python脚本构建apk为此,我使用googlecollab.这里是main.py脚本:importyoutube_dlfromkivy.appimportAppfromkivy.uix.boxlayoutimportBoxLayoutfromkivy.uix.buttonimportButtonfromkivy.uix.tex......
  • 自动解码并检索 S/MIME 加密电子邮件的正文 (python)
    我如何:用python代码连接我的邮件收件箱以自动获取未读电子邮件的加密内容;解码S/MIME加密电子邮件(我有密钥);检索电子邮件正文纯文本;检查正文(或主题)是否与某个关键字(现在为“test”)匹配,并在匹配时打印一些内容;在树莓派上使用此代码,无需手动......
  • Python 3 写入 DBF(带有 Memo 的 dBase IV)
    我需要在Python3中写入带有备注字段的dBaseIVdbf文件,但找不到合适的模块来执行此操作。我尝试过的包:Simpledbf-只读dbf-不支持dBaseIVdbfpy-不支持Python3dbfpy3-不支持dBaseIVYDbf-不支持备注字段pyshp-无法仅使用dbf文件......
  • Robin-Stocks Python 中的 order_buy_fractional_by_price 问题
    我在Robin-StocksPython包中的order_buy_fractional_by_price函数中遇到问题。在正常市场交易时间内下达以美元为基础的买入订单时,该订单被错误地设置为限价订单。对我来说看起来有问题的代码似乎是导致此问题的原因。我尝试在包管理器中本地修改或删除有问题的代码,但遇......