尝试在 Mac M1 上将 scikit-learn 导入 PyCharm

Trying to import scikit-learn to PyCharm on Mac M1

我想在 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

所以我尝试 Google 解决方案并了解到 Python 在 M1 Mac 上存在某些问题。我尝试了什么:

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

The recently introduced macos/arm64 platform (sometimes also known as macos/aarch64) requires the open source community to upgrade the build configuration and automation to properly support it.

At the time of writing (January 2021), the only way to get a working installation of scikit-learn on this hardware is to install scikit-learn and its dependencies from the conda-forge distribution, for instance using the miniforge installers

  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

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

从技术上讲,您永远不会将任何东西安装到 PyCharm 中,而是安装到 python 安装中,这又可以是 virtualenv 或 conda env(环境中的 env)。如果您设法将 PyCharm 指向正确的 python 可执行文件,那您应该没问题。另一方面,如果您 conda/pip 安装到终端的其他环境中,您会感到困惑。因为我没有 M1 Mac 不过我不能确切地说出你哪里出错了。