bbalasub1 / glmnet_python

GNU General Public License v3.0
199 stars 94 forks source link

Glmnet Compatibility with M1 MacBooks (Solved) #59

Open skbwu opened 2 years ago

skbwu commented 2 years ago

Hi everybody,

I had some trouble getting glmnet_python to work with my M1 MacBook Pro (Late 2020). Some error messages I received included "OSError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/tensorflow/lib/python3.9/site-packages/glmnet_py/GLMnet.so, 0x0006): tried: '/opt/homebrew/Caskroom/miniforge/base/envs/tensorflow/lib/python3.9/site-packages/glmnet_py/GLMnet.so' (not a mach-o file), '/usr/local/lib/GLMnet.so' (no such file), '/usr/lib/GLMnet.so' (no such file)"

I just wanted to share my solution that finally got it to work:

  1. Create a virtual conda environment, but force it to only install and use legacy x86-64 packages. The specific instructions for this step can be found here.
  2. Install glmnet_py using pip in this specific environment as usual.
  3. Replace the GLMnet.so file from the pip installation with the GLMnet.so file from here.
  4. Replace "scipy.floor(nobs/nfolds)" in line 260/261 of cvglmnet.py with "int(scipy.floor(nobs/nfolds))". The source of this fix can be found here.

Hope this helps!