Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to import scikit-learn to PyCharm on Mac M1

I’m new to Python, so please excuse me in advance for possible silly mistakes

I wanted to install the sklearn package in PyCharm to use in one of my projects. However, I was unable to do so, I always got the same mistake (below is an extract):

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 "

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

So I tried to Google the solution and learned that there are certain problems with Python on a M1 Mac. What I tried:

  1. I tried to use a solution from another stack overflow question, but I guess I wasn’t smart enough to follow the steps, so it didn’t really help
  2. I tried to follow instructions on the scikit official site, but again, I didn’t understand what to do with miniforge installers:

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. I also tried to install the package with Miniforge. I managed to install the package in a virtual environment, but I still couldn’t import sklearn to my project:

    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. I also tried lots of other things I found on the Web, but nothing helped, unfortunately

I feel like I’ve done a lot of unnecessary stuff so far, but I’d still really like to solve this problem. My Python version is 3.10 (I also tried 3.9 in a virtual environment) and my PyCharm version is 2021.2.2

Any help is much appreciated. Thank you!

>Solution :

I think the easiest approach is to create a conda environment from PyCharm. Go to the python interpreter settings and create a new conda environment from there. Then, install packages with conda inside that environment, all from inside PyCharm.

Technically speaking, you’re never installing anything into PyCharm, but into a python installation, which can again either be a virtualenv or a conda env (env as in environment). If you manage to point PyCharm to the correct python executable, you should be good. On the other hand if you’re conda/pip installing into some other environment in the terminal, you’ll just be confused. Since I don’t have an M1 Mac I can’t say exactly where you went wrong, though.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading