question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Installing spaCy with OpenMP support on OS X

See original GitHub issue

I have successfully built and installed spaCy 0.100.7 with OpenMP on OS X for brew installed python. For the impatient among us, here are instructions on how to do it yourself.

Choose your adventure:

  1. Install python:
    • brew install python
    • Other distributions such as Anaconda may work as well. Please let us know if you are successful!
  2. (choose one):
    • llvm-3.8
    • clang-omp
    • GCC (Warning: segfauts #266)
  3. Edit setup.py, then build and test spacy
  4. Install spacy

Note that these instructions are for brew installed python.

Option: LLVM-3.8

  1. Download the LLVM-3.8 binaries:

  2. Install the binaries:

    For example, to install at /opt/llvm38:

    tar xJf clang+llvm-3.8.0-x86_64-apple-darwin.tar.xz
    sudo mkdir -p /opt
    sudo mv clang+llvm-3.8.0-x86_64-apple-darwin /opt/llvm38
    
  3. Tell pip to use clang-3.8:

    export CC=/opt/llvm38/bin/clang
    export CXX=/opt/llvm38/bin/clang++
    export PATH=/opt/llvm38/bin:$PATH
    export C_INCLUDE_PATH=/opt/llvm38/include:$C_INCLUDE_PATH
    export CPLUS_INCLUDE_PATH=/opt/llvm38/include:$CPLUS_INCLUDE_PATH
    export LIBRARY_PATH=/opt/llvm38/lib:$LIBRARY_PATH
    export DYLD_LIBRARY_PATH=/opt/llvm38/lib:$DYLD_LIBRARY_PATH
    

Option: Clang-OMP

  1. Install clang-omp Homebrew:

    brew install clang-omp
    
  2. Tell pip to use clang-omp:

    export CC=clang-omp
    export CXX=clang-omp
    export PATH=/usr/local/bin:$PATH
    export C_INCLUDE_PATH=/usr/local/include/libiomp:$C_INCLUDE_PATH
    export CPLUS_INCLUDE_PATH=/usr/local/include/libiomp:$CPLUS_INCLUDE_PATH
    export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
    export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
    

Option: GCC

  1. Install GCC via Homebrew:

    brew install gcc --without-multilib
    

    The --without-multilib option is required for OpenMP support.

  2. Tell pip to use GCC:

    export CC=gcc-5
    export CXX=g++-5
    

WARNING: Compiling with GCC as of spaCy 0.100.5 may result in a segfault (#266).

Required: edit setup.py and install

Follow the ‘Compile from source’ instructions from spaCy documentation, with the following adjustments.

git clone https://github.com/honnibal/spaCy.git
cd spaCy
git checkout 0.100.6 # or 'master' if you wish

Edit setup.py lines 88-90 to enable OpenMP:

# if not sys.platform.startswith('darwin'):
compile_options['other'].append('-fopenmp')
link_options['other'].append('-fopenmp')

Now continue with the install instuctions as per the documentation.

virtualenv .env && source .env/bin/activate
export PYTHONPATH=`pwd`
pip install -r requirements.txt
python setup.py clean
pip install -e .
python -m spacy.en.download
pip install pytest
py.test spacy/tests/

To install spaCy outside of virtualenv and/or outside the source directory:

  1. Deactivate virtualenv using the deactivate command.
  2. Run pip install . in the source directory.
  3. For clang/llvm, add the appropriate library path:
    • clang-omp: export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
    • llvm38: export DYLD_LIBRARY_PATH=/opt/llvm38/lib:$DYLD_LIBRARY_PATH

Relevant resources:

Thank you for the help @honnibal @henningpeters @gushecht !

History:

  • May 9 2016: Add instructions for LLVM-3.8 and use deactivate virtualenv command.
  • use pip install -e . instead of python setup.py build_ext --inplace
  • add instructions for installing outside of virtualenv.
  • Update for 0.100.6

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
gushechtcommented, Mar 11, 2016

Hey all, looks like pip install -e . was the magic formula!

For final reference:

brew install python

brew install clang-omp

git clone https://github.com/honnibal/spaCy.git

cd spaCy
git checkout 0.100.5
# Make the specified changes to setup.py

export CC=clang-omp
export CXX=clang-omp
export PATH=/usr/local/bin:$PATH
export C_INCLUDE_PATH=/usr/local/include/libiomp:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/include/libiomp:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH

virtualenv .env && source .env/bin/activate

export PYTHONPATH=`pwd`
pip install -r requirements.txt

python setup.py clean

pip install -e .

Thanks so much to each of you.

2reactions
sadovnychyicommented, Nov 14, 2016

As per today clang-omp is deprecated and moved to homebrew/boneyard/clang-omp. You should use brew install llvm instead.

Environment variables I used before pip installation:

export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++
export PATH=/usr/local/opt/llvm/bin:$PATH
export C_INCLUDE_PATH=/usr/local/opt/llvm/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/opt/llvm/lib:$LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/opt/llvm/lib:$DYLD_LIBRARY_PATH

Got about 2X speed up after this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Install spaCy · spaCy Usage Documentation
spaCy is compatible with 64-bit CPython 3.6+ and runs on Unix/Linux, macOS/OS X and Windows. The latest spaCy releases are available over pip...
Read more >
spacy 1.5.1 - PyPI
Install spaCy. spaCy is compatible with 64-bit CPython 2.6+/3.3+ and runs on Unix/Linux, OS X and Windows. Source packages are available ...
Read more >
Installation for Mac OSX — NLSAM 0.6.1 documentation
Spams and openmp support¶. A. The lazy way, using conda forge channel¶. The old installation instruction would have you install a non openmp...
Read more >
successful spacy installation on mac m1, unsuccessful import
I tried re-installing/creating a new environment with spacy using this thread for mac m1 but it still doesn't seem to work.
Read more >
Packages for macOS on x86_64 with Python 3.7
Name Version Summary / License _libgcc_mutex 0.1 Mutex for libgcc and libgcc‑ng / None aiofiles 0.7.0 File support for asyncio / Apache 2.0 alembic 1.8.1 A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found