Skip to content

Instantly share code, notes, and snippets.

@yatsu
Created April 5, 2020 10:31
Show Gist options
  • Save yatsu/47bdde35e8abbe7d14bbe730342aa9e0 to your computer and use it in GitHub Desktop.
Save yatsu/47bdde35e8abbe7d14bbe730342aa9e0 to your computer and use it in GitHub Desktop.
Install numpy with enabling openblas using pip on macOS
# Setup HomeBrew: https://brew.sh/
brew install openblas
pip download --no-binary :all: --no-deps numpy
unzip numpy-1.18.2.zip # (you may have newer version)
cd numpy-1.18.2
cat > site.cfg <<EOF
[openblas]
libraries = openblas
library_dirs = $(brew --prefix openblas)/lib
include_dirs = $(brew --prefix openblas)/include
runtime_library_dirs = $(brew --prefix openblas)/lib
EOF
pip install .
# Check the installed numpy config
# (Note that you must leave the numpy source directory to run this)
python3 -c "import numpy; numpy.show_config()"
# Test the performance with test_numpy.py (https://gist.github.com/alimuldal/eb0f4eea8af331b2a890)
OMP_NUM_THREADS=1 python test_numpy.py
OMP_NUM_THREADS=8 python test_numpy.py
@kailichou
Copy link

It worked for my numpy-1.19.4 at Big Sur. Thank you
Do you know how to solve this one?

kailichou$ python -c "import numpy; import pandas"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/__init__.py", line 51, in <module>
    from pandas.core.api import (
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/core/api.py", line 31, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/core/groupby/generic.py", line 65, in <module>
    from pandas.core.frame import DataFrame
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/core/frame.py", line 119, in <module>
    from pandas.core import algorithms, common as com, generic, nanops, ops
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/core/generic.py", line 112, in <module>
    from pandas.io.formats import format as fmt
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/io/formats/format.py", line 77, in <module>
    from pandas.io.common import stringify_path
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pandas/io/common.py", line 3, in <module>
    import bz2
  File "/Users/kailichou/.pyenv/versions/3.8.3/lib/python3.8/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

@yatsu
Copy link
Author

yatsu commented Jan 2, 2021

Probably you have lost or broken libbz2 which had been used by Python.

Try this gist to reinstall Python.
https://gist.github.com/yatsu/9ae2dc633511d6d97efccd4fcfa8c8b1

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