【问题标题】:Trying to import scikit-learn to PyCharm on Mac M1尝试在 Mac M1 上将 scikit-learn 导入 PyCharm
【发布时间】:2022-02-07 23:42:53
【问题描述】:

我想在 PyCharm 中安装 sklearn 包。但是,我总是遇到同样的错误(以下是摘录):

pip install scikit-learn  # input


Collecting scikit-learn
  Using cached scikit-learn-1.0.2.tar.gz (6.7 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [148 lines of output]
      Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_system != "AIX" 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.27-py2.py3-none-any.whl (983 kB)
      Collecting oldest-supported-numpy
        Using cached oldest_supported_numpy-2022.1.30-py3-none-any.whl (3.9 kB)
      Collecting scipy>=1.1.0
        Using cached scipy-1.8.0.tar.gz (38.3 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 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error
      
        × Preparing metadata (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [116 lines of output]
            setup.py:482: UserWarning: Unrecognized setuptools command ('dist_info --egg-base /private/var/folders/bh/bybj2bp10dvdq7ljmr_697mw0000gn/T/pip-modern-metadata-h78sgevf'), proceeding with generating Cython sources and expanding templates
              warnings.warn("Unrecognized setuptools command ('{}'), proceeding with "


raise NotFoundError(msg)
            numpy.distutils.system_info.NotFoundError: No BLAS/LAPACK libraries found. Note: Accelerate is no longer supported.
            To build Scipy from sources, BLAS & LAPACK libraries need to be installed.
            See site.cfg.example in the Scipy source directory and
            https://docs.scipy.org/doc/scipy/reference/building/index.html for details.
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: metadata-generation-failed

所以我尝试用谷歌搜索解决方案,并了解到 Python 在 M1 Mac 上存在某些问题。我尝试了什么:

  1. 我尝试使用另一个 stack overflow question 的解决方案,但我想我不够聪明,无法遵循这些步骤,所以它并没有真正帮助
  2. 我尝试按照 scikit official site 上的说明进行操作,但我还是不明白如何处理 miniforge 安装程序:

最近推出的 macos/arm64 平台(有时也称为 macos/aarch64) 需要开源社区升级构建 配置和自动化以正确支持它。

在撰写本文时(2021 年 1 月),获得工作的唯一方法 在此硬件上安装 scikit-learn 是为了安装 scikit-learn 及其依赖于 conda-forge 发行版, 例如使用 miniforge 安装程序

  1. 我还尝试使用Miniforge 安装软件包。我设法在虚拟环境中安装该软件包,但我仍然无法导入 sklearn 到我的项目:

    conda list scikit-learn  # input
    
    # packages in environment at /opt/homebrew/Caskroom/miniforge/base/envs/test_env:
    #
    # Name                    Version                   Build  Channel
    scikit-learn              1.0.2            py39hef7049f_0    conda-forge
    
  2. 我还尝试了很多我在网上找到的其他东西,但没有任何帮助,很遗憾

我觉得到目前为止我已经做了很多不必要的事情,但我仍然很想解决这个问题。我的 Python 版本是 3.10(我也在虚拟环境中尝试过 3.9),我的 PyCharm 版本是 2021.2.2

【问题讨论】:

    标签: python scikit-learn python-import


    【解决方案1】:

    我认为最简单的方法是从 PyCharm 创建一个 conda 环境。转到 python 解释器设置并从那里创建一个新的 conda 环境。然后,在该环境中安装带有 conda 的软件包,所有这些都来自 PyCharm。

    从技术上讲,您永远不会在 PyCharm 中安装任何东西,而是在 python 安装中,它可以再次是 virtualenv 或 conda env(环境中的环境)。如果您设法将 PyCharm 指向正确的 python 可执行文件,那么您应该很好。另一方面,如果您将 conda/pip 安装到终端中的其他环境中,您只会感到困惑。不过,由于我没有 M1 Mac,我无法准确说出您哪里出错了。

    【讨论】:

    • 嗯,说实话,这真的很尴尬。我一直在尝试找到解决方案 5 个小时,而您设法在几秒钟内解决了我的问题。它工作得很好。这对我来说意味着世界,你真的救了我。非常感谢!!
    • 太好了,很高兴听到这个消息!
    • 现在是 2022 年,不幸的是,Conda 仍然是 Python 中唯一一个对我来说在所有平台上开箱即用的东西。我认为现在 Python 设置会好一些。
    猜你喜欢
    • 1970-01-01
    • 2019-01-10
    • 2020-03-09
    • 2019-08-27
    • 2021-08-18
    • 2021-10-07
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多