Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native wheels for the macos/arm64 platform (Apple Silicon M1 hardware) #19137

Closed
3 of 5 tasks
Tracked by #627
ogrisel opened this issue Jan 8, 2021 · 34 comments · Fixed by #21827 or #27067
Closed
3 of 5 tasks
Tracked by #627

Native wheels for the macos/arm64 platform (Apple Silicon M1 hardware) #19137

ogrisel opened this issue Jan 8, 2021 · 34 comments · Fixed by #21827 or #27067

Comments

@ogrisel
Copy link
Member

ogrisel commented Jan 8, 2021

Making this happen depends on the resolution of the following upstream issues:

Note: macos/arm64 is also known as macos/aarch64.

@ogrisel
Copy link
Member Author

ogrisel commented Jan 8, 2021

In the mean time, users are recommended to use the macos/arm64 packages of conda-forge by using the miniforge or mambaforge installers:

https://github.com/conda-forge/miniforge

@ogrisel
Copy link
Member Author

ogrisel commented Feb 19, 2021

Note that we could provide both macos/arm64 wheels and universal2 wheels, assuming that numpy and scipy do it.

universal2 wheels for numpy and scipy might be challenging to generate because those vendor openblas which has to be partially built by gfortran which cannot natively generate fat universal2 binaries. scipy also has other fortran compiled extensions (l-bfgs, arpack....). An additional merge operation would have to be performed to generate such fat binaries.

For scikit-learn, we do not need to build anything in fortran and clang can natively generate fat binaries for C/C++ compiled extensions (using cibuildwheel).

@UnixJunkie
Copy link
Contributor

Forcing people to use conda/miniconda. Oh my god...
conda: the worst package manager I have ever encountered in my life (apart from an install from scratch, it doesn't know how to do anything in a timely manner).

PS: thanks for the workaround though

@grisaitis
Copy link

grisaitis commented Jun 22, 2021

conda: the worst package manager I have ever encountered in my life

Haha, have you never used pipenv? Or the R programming language?

Be grateful, very grateful.

@UnixJunkie
Copy link
Contributor

I don't know pipenv.

PS: The R package manager is pretty good, in my experience.

@jnothman
Copy link
Member

jnothman commented Jun 24, 2021 via email

@anirudh-g
Copy link

Hi All. Is there any update on this issue?

@csp197
Copy link

csp197 commented Oct 5, 2021

@ogrisel
Scipy provides nightly wheel builds for arm64 - scipy/scipy#13409 (comment)

Is this something that sklearn can provide as well?
Conda workaround is a good temp fix, but not great for long term...

@Mantower
Copy link

Mantower commented Oct 6, 2021

Hi.

I found this fix that seems to install scikit without the need of using conda

# SciPy:
python -m pip install --no-cache --no-use-pep517 pythran cython pybind11 gast"==0.4.0"
pyenv rehash
python -m pip install --no-cache --no-binary :all: --no-use-pep517 scipy"==1.7.1"

# Scikit-Learn
python -m pip install --no-use-pep517 scikit-learn"==0.24.2"

In my case the scikit line was sufficient as I had already installed cython and scipy beforehand.
Good luck!

Edit: A thought I just had; it might be that you can change the version number to 1.0.0, but this isn't something I've tested myself.

@appleseedexm
Copy link

appleseedexm commented Oct 8, 2021

Hi.

I found this fix that seems to install scikit without the need of using conda
[...]

This lead me on the right path, however I had to install nightly scipy instead. Afterwards I was able to install scikit-learn 1.0.0 without a problem:

# SciPy:
python -m pip install --no-cache --no-use-pep517 pythran cython pybind11 gast"==0.4.0"
pyenv rehash
python -m pip install --pre -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy

# Scikit-Learn
python -m pip install --no-use-pep517 scikit-learn"==1.0.0"

@HRezaei
Copy link

HRezaei commented Oct 17, 2021

Hi.
I found this fix that seems to install scikit without the need of using conda
[...]

This lead me on the right path, however I had to install nightly scipy instead. Afterwards I was able to install scikit-learn 1.0.0 without a problem:

# SciPy:
python -m pip install --no-cache --no-use-pep517 pythran cython pybind11 gast"==0.4.0"
pyenv rehash
python -m pip install --pre -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy

# Scikit-Learn
python -m pip install --no-use-pep517 scikit-learn"==1.0.0"

For me it worked even without pyenv rehash, I hadn't pyenv installed.

@MikhailKravets
Copy link

MikhailKravets commented Oct 18, 2021

Finally, I fixed this problem for myself. I was able to build scikit-learn. You may find the wheel and the instruction on how to install scikit-learn on M1 in this repo.

My problem was in scipy. I couldn't build it myself. But the guys from Anaconda did it 🎉 .

So installation instruction. Pipenv

  1. Look for required scipy in Anaconda's pypi
  2. Download scipy from Anaconda's pypi
  3. Download scikit-learn from this repository
  4. Place them at .wheels directory of your project
  5. Edit your Pipfile to have these lines included
scipy = {versions = "*", markers = "platfotm_machine != 'arm64'"}
scipy-m1 = {path = ".wheels/scipy-1.8.0.dev0+1753.a063cf3-cp38-cp38-macosx_11_0_arm64.whl", markers = "platfotm_machine == 'arm64'"}

scikit-learn = {versions = "*", markers = "platfotm_machine != 'arm64'"}
scikit-learn-m1 = {path = ".wheels/scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl", markers = "platfotm_machine == 'arm64'"}
  1. Run pipenv install --skip-lock && pipenv lock --pre

Installation instruction. Pip

  1. Download scikit-learn from this repository
  2. Place it at .wheels directory of your project
  3. Install scipy from Anaconda
pip install scipy --index-url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
  1. Install scikit-learn
pip install .wheels/scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl

@sunilshah
Copy link

sunilshah commented Oct 18, 2021

I have homebrew installed python 3.9.7 and scipy version 1.7.1.

I had a version of scikit-learn installed from dev 1.0 source of March 3, 2021.

I installed versions 1.0

pip3 install -U --no-use-pep517 scikit-learn

It works fine.

However, in my testing of linear_model, compared to the same version running on Rosetta2, the native code on M1 runs 1.67x slower! Almost all other numerical codes run faster in native mode.

@nimafanniasl
Copy link

nimafanniasl commented Oct 26, 2021

i have an proplem to install sklearn:

PS C:\Users\Nima> pip install -U scikit-learn
Collecting scikit-learn
  Downloading scikit-learn-1.0.1.tar.gz (6.6 MB)
     |████████████████████████████████| 6.6 MB 136 kB/s
  Installing build dependencies ... -

it is staying in here!

python 3.10.0 64-bit

@danieltomasz
Copy link

danieltomasz commented Oct 26, 2021

There was a problem with scipy with 3.10, maybe trying with 3.9 will help scipy/scipy#13102 (comment)
Also try upgrading pip, sometimes it helps with new wheels

@ShashankKrishnaV
Copy link

Hi.
I found this fix that seems to install scikit without the need of using conda
[...]

This lead me on the right path, however I had to install nightly scipy instead. Afterwards I was able to install scikit-learn 1.0.0 without a problem:

# SciPy:
python -m pip install --no-cache --no-use-pep517 pythran cython pybind11 gast"==0.4.0"
pyenv rehash
python -m pip install --pre -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy

# Scikit-Learn
python -m pip install --no-use-pep517 scikit-learn"==1.0.0"

You are literally a saviour for me. I am trying it for nearly 4 hrs now.

@SiddyP
Copy link

SiddyP commented Nov 1, 2021

Can confirm this is working on M1 (python 3.8, nightly build of scipy)
pip3 install -U --no-use-pep517 scikit-learn

If you have issues make sure you also have Cython >= 0.28.5 installed.

@xiangpeng2008
Copy link

Can confirm this is working on M1 (python 3.8, nightly build of scipy) pip3 install -U --no-use-pep517 scikit-learn

If you have issues make sure you also have Cython >= 0.28.5 installed.

pip3 install -U --no-use-pep517 scikit-learn doesn't work for me, but python -m pip install --no-use-pep517 scikit-learn"==1.0.0" works

@MarcoTerzulli
Copy link

MarcoTerzulli commented Nov 4, 2021

Can confirm this is working on M1 (python 3.8, nightly build of scipy) pip3 install -U --no-use-pep517 scikit-learn

If you have issues make sure you also have Cython >= 0.28.5 installed.

Unfortunately, it's not working for me. I'm on Python 3.9 and M1 Pro. I'm still getting the same error.

I hope there's a way for installing it without needing to use Conda.

EDIT: I managed to install it using the method posted in MikhailKravets comment above.

@danieltomasz
Copy link

Can confirm this is working on M1 (python 3.8, nightly build of scipy) pip3 install -U --no-use-pep517 scikit-learn
If you have issues make sure you also have Cython >= 0.28.5 installed.

Unfortunately, it's not working for me. I'm on Python 3.9 and M1 Pro. I'm still getting the same error.

I hope there's a way for installing it without needing to use Conda.

Do you have the latest pip?

@MarcoTerzulli
Copy link

Can confirm this is working on M1 (python 3.8, nightly build of scipy) pip3 install -U --no-use-pep517 scikit-learn
If you have issues make sure you also have Cython >= 0.28.5 installed.

Unfortunately, it's not working for me. I'm on Python 3.9 and M1 Pro. I'm still getting the same error.
I hope there's a way for installing it without needing to use Conda.

Do you have the latest pip?

Yes, just checked

@MarcoTerzulli
Copy link

MarcoTerzulli commented Nov 4, 2021

Installation instruction. Pip

  1. Download scikit-learn from this repository
  2. Place it at .wheels directory of your project
  3. Install scipy from Anaconda
pip install scipy --index-url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
  1. Install scikit-learn
pip install .wheels/scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl

I finally managed to install it. I have already tried this morning, but probably I messed something.
Python 3.9, latest version of pip, and M1 Pro

@Karan-S-Mittal
Copy link

thanks this works for me. and using miniforge is also quite similar.
I had some libraries which were depended on scipy so installing it this way, it makes other pip installs very easy on m1.

@matteosantama
Copy link

Do the maintainers plan to backport M1 functionality to sklearn<1.0.0? In other words, should M1 users expect to only be able to use sklearn version 1.0.0 and later?

@minhashemi
Copy link

Installation instruction. Pip

  1. Download scikit-learn from this repository
  2. Place it at .wheels directory of your project
  3. Install scipy from Anaconda
pip install scipy --index-url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
  1. Install scikit-learn
pip install .wheels/scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl

How to put the downloaded package in .wheels directory? I use visual studio code on M1 MacBook Pro MacOS Monterey

@MikhailKravets
Copy link

You can keep the downloaded package at whatever directory you want. .wheels is just an example. You can place it in the project root then

pip install scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl

@rgommers
Copy link
Contributor

pip install scipy --index-url=https://pypi.anaconda.org/scipy-wheels-nightly/simple

Just a note on these: they may crash your OS if you're on macOS 11. It's recommended to upgrade to macOS 12. SciPy wheels for macOS >=12 should be coming soon: https://mail.python.org/archives/list/scipy-dev@python.org/thread/LLN2O4G2XI2MPILRW2XRRVCUK336WGKF/.

@danieltomasz
Copy link

Scipy just released 1.7.3 with binary wheels
https://github.com/scipy/scipy/releases/tag/v1.7.3

@zoeyliu1999
Copy link

Installation instruction. Pip

  1. Download scikit-learn from this repository
  2. Place it at .wheels directory of your project
  3. Install scipy from Anaconda
pip install scipy --index-url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
  1. Install scikit-learn
pip install .wheels/scikit_learn-1.1.dev0-cp39-cp39-macosx_11_0_universal2.whl

I finally managed to install it. I have already tried this morning, but probably I messed something. Python 3.9, latest version of pip, and M1 Pro

I already installed the sklearn but it still has somthing wrong.

numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

@alexcombessie
Copy link

Hi,

Any updates of this - for folks like me who don't want conda, just pip ?

Cheers,

Alex

@sunilshah
Copy link

Hi,

Any updates of this - for folks like me who don't want conda, just pip ?

Cheers,

Alex

On Mac OS 12.2, I have been running scikit-learn 1.0.2 in native mode. Scipy 1.7.3 and python 3.9.10 were installed using homebrew. I used pip3 install -U --no-use-pep517 scikit-learn

@turnUpTheChill
Copy link

FWIW, running on an M1 I found using docker to run a jupyter notebook was the only viable work-around I could use

@peterfortuin
Copy link

I'm looking forward to use scikit-learn on my M1 Macbook. Keep up the good work!

@peartobear
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet