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

[Bug]: Installing PyBaMM on M1 chip fails (both pip and install from source) #2346

Closed
Saransh-cpp opened this issue Oct 5, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@Saransh-cpp
Copy link
Member

Saransh-cpp commented Oct 5, 2022

PyBaMM Version

all

Python Version

3.9

Describe the bug

PyBaMM cannot be installed on an M1 mac from pip as well as from source. I think casadi does not support M1 chips?

I was able to set everything up by installing casadi from source, and removing casadi as a dependency when installing PyBaMM from source. Should this be documented in the installation page?

Also, should we be specifically building intel wheels till casadi supports M1 wheels? This way users will get a "No matching distribution found for pybamm" error when installing through pip on M1, rather than than the installation failing midway.

Building casadi locally -

brew install cmake swig
git clone https://github.com/casadi/casadi.git casadi
cd casadi
git checkout 3.5.5
mkdir build
cd build
cmake -DWITH_PYTHON=ON \
-DWITH_PYTHON3=ON \
-DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
..
make
sudo make install

Steps to Reproduce

pip3 install pybamm
pip3 install -e .

Relevant log output

ERROR: Could not find a version that satisfies the requirement casadi>=3.5.0 (from pybamm) (from versions: none)
ERROR: No matching distribution found for casadi>=3.5.0
@Saransh-cpp Saransh-cpp added the bug Something isn't working label Oct 5, 2022
@valentinsulzer
Copy link
Member

I'm able to install pybamm on M1 from source, but maybe it's using Rosetta?

@Saransh-cpp
Copy link
Member Author

I think so. #2072 looks related (casadi not found), the only difference is that I did not try building up the IDAKLUSolver.

@aabills
Copy link
Contributor

aabills commented Nov 6, 2022

You can force it to use rosetta if you're using conda by setting the environment variable CONDA_SUBDIR to osx-x64.

https://towardsdatascience.com/how-to-manage-conda-environments-on-an-apple-silicon-m1-mac-1e29cb3bad12

Actually I think this maybe only works with miniconda

Actually this breaks numpy

@savvn001
Copy link

savvn001 commented Nov 24, 2022

I managed to get it to install and sort of work.
Using an M1 MBA (2020):

  • Download and install Python 3.8.10 universal installer (maybe 3.9 works too, I haven't tried)
  • Use the interpreter /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-intel64 to create a venv and run the usual pip install pybamm from inside that environment.

I think using the intel64 binary, which I guess automatically runs under rosetta, seems to work? When I run a script after doing import pybamm it does take about ~4 secs to start running. Not sure if this is how it usually is with this package.

@ndrewwang
Copy link
Contributor

ndrewwang commented Dec 16, 2022

@savvn001's method on Python 3.8.10 + M2 MBP + MacOS 12.5 works for me - it did not work with 3.9.

Specifically:
0. From within a rosetta terminal:

  1. Installed 3.8.10 from https://www.python.org/downloads/release/python-3810/
  2. Created a virtual environment based on the intel64 interpreter: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-intel64 -m venv venv38intel
  3. For usage in jupyter lab, added the kernel ipython kernel install --user --name=venv38intel
  4. Activated the venv source venv38intel/bin/activate

@aabills
Copy link
Contributor

aabills commented Dec 16, 2022

conda-forge should also work (no rosetta required)

@rtimms
Copy link
Contributor

rtimms commented Feb 7, 2023

FYI the following worked for me on Python 3.9.13 + M2 Macbook Air + MacOS 13.2

  1. Installed Python 3.9.13 universal installer from here
  2. Created a virtual env using the intel64 interpreter /Library/Frameworks/Python.framework/Versions/3.9/bin/python3-intel64 -m venv env
  3. Activate and install as normal

@CLOUDUH
Copy link

CLOUDUH commented Mar 1, 2023

I made it!
Device & system version:
MacBook Pro 14 2021 (M1 Pro chip) / MacOS 12.6

Virtual environment manager:
Anaconda 22.11.0 64-Bit (M1) Graphical Installer (484 MB)
Python installed with this version uses the ARM architecture by default, like: osx-arm64::numpy-1.24.2-py39hff61c6a_0

Steps:

  1. Create a new environment based on Python 3.9: conda create -n battery python=3.9
  2. Activate environment: conda activate battery
  3. Forced use conda-forge to install PyBaMM: conda install -c conda-forge pybamm
  4. Activate and enjoy.

I ran into some network problems: Downloading and Extracting Packages , but they were quickly resolved.

@aabills
Copy link
Contributor

aabills commented Mar 2, 2023

Out of curiosity has anyone checked if there's a performance difference between Conda/build-from-source and the rosetta options?

@Saransh-cpp
Copy link
Member Author

Casadi has started building wheels for M1/M2 in their nightly-develop releases - https://github.com/casadi/casadi/releases/tag/nightly-develop

@agriyakhetarpal
Copy link
Member

Casadi 3.6.0 brings support for Apple Silicon: https://github.com/casadi/casadi/releases/tag/3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants