Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Created February 26, 2019 15:29
Show Gist options
  • Select an option

  • Save jarmitage/40e3b7962b0a77a233b2d590d69378d6 to your computer and use it in GitHub Desktop.

Select an option

Save jarmitage/40e3b7962b0a77a233b2d590d69378d6 to your computer and use it in GitHub Desktop.
How to install Essentia on macOS using an Anaconda environment

How to install Essentia on macOS using an Anaconda environment

[This is a brief note so I don't forget how to do this, and will probably be technically obsolete before long!]

Essentia is an "Open-source library and tools for audio and music analysis, description and synthesis" (https://essentia.upf.edu)

If you use Jupyter Lab / notebooks and therefore manage your Python environments using Anaconda, AND your machine is macOS, you will not be able to install Essentia out of the box. This is because:

If you try to install Essentia from source (https://essentia.upf.edu/documentation/installing.html) using an Anaconda environment on macOS, you will find that a bug in CPython means that ./waf configure [...] fails:

However:

  1. homebrew's Python does not suffer from the same issue
  2. The issue above is only relevant in the configure step and not the install steps.

So! A hacky, ugly, probably broken somewhere/somehow workaround, is:

  • Do ./waf configure [...] using Python installed via homebrew (brew install python) rather than Anaconda
  • Then complete the rest of the installation using Anaconda's Python

Your essentia installation may end up in /usr/local/lib/python3.7/site-packages/, so you then need to add this to your Anaconda path:

import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/') # not permanent

Now you should be able to import essentia from your Anaconda environment.

Yes, I did say it's ugly.

@carolska
Copy link

Hello! Noobie questions:

Could you please provide details about the steps you used?

What should be preceded by this ./waf configure [...] ? something like brew tap MTG/essentia ./waf configure [...] ???

Then complete the rest of the installation using Anaconda's Python

should this be brew tap MTG/essentia or conda install essentia?

Can you please post which lines of command should I use in terminal for the two main steps?

@jarmitage
Copy link
Author

Hi @carolska,

I'm afraid I don't remember more specifically than what I wrote here.

But, I would recommend you to ask on MIR community Slack because hopefully there's a better way to do this now than in my notes above!

https://launchpass.com/mircommunity

Good luck.

@fmiramar
Copy link

fmiramar commented Sep 6, 2019

Hey! Here is an noobs step-by-step guide for installing essentia for anaconda on mac osx:

1 - Install anaconda
2 - install homebrew
3 - Install command line tools for XCode. Open terminal and type:
xcode-select --install
4 - Install essentia prerequisites, on terminal type the following:
brew install pkg-config gcc readline sqlite gdbm freetype libpng
5 - Install essentia dependencies, on terminal type the following:
brew install libyaml fftw ffmpeg libsamplerate libtag

Installing essentia:
6 -On Terminal, run the following line to install essentia's latest version. It will take a while and use a lot of cpu because many tests will ensure that all the algorithms are working properly (./waf part of the installation).
brew install essentia --HEAD
If there are no big warnings then you have installed it successfully.

7 - Essentia will not be installed in the default location of conda packages, so we can manage this in two ways:
Option 1 - If you want to set essentia as a default package, so you dont need to add a path to it all the time, run the following line on terminal:
conda-develop /usr/local/lib/python3.7/site-packages/
Now you can open spyder, jupiter, IPython console or open python on terminal and you will be able to load essentia with import essentia

Option 2 - If you want to use essentia only ocasionaly, then you can open spyder, jupiter, IPython console or open python on terminal and run the following:

import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')

then load essentia with import essentia

@jarmitage
Copy link
Author

jarmitage commented Sep 6, 2019

Thanks @fmiramar :) cc @carolska

@xaviliz
Copy link

xaviliz commented Jan 28, 2020

Thanks a lot @fmiramar and @carolska

An important note: the version of python interpreter used to compile Essentia should be the same as the one used in the virtual environment. Otherwise an ImportError is generated.

python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import essentia
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/essentia/__init__.py", line 1, in <module>
    from . import _essentia
ImportError: cannot import name '_essentia'

@zseramnay
Copy link

Hello

I did :
import sys
sys.path.append('/usr/local/lib/python3.9/site-packages/')
import essentia

and I get :

--
ImportError: cannot import name '_essentia' from partially initialized module 'essentia' (most likely due to a circular import) (/usr/local/lib/python3.9/site-packages/essentia/init.py)

I dont know how to fix this..
Thanks

Yan

@xaviliz
Copy link

xaviliz commented Jul 5, 2021

Hi, I found another way to install essentia in a virtual environment or conda environment. Maybe it is useful for you.

  1. Create a virtual environment, you might use venv,
python3 -m venv env

or conda,

conda create -n cenv python=3.8

For installing packages in the virtual environment:

  1. Activate your env:
source env/bin/activate

or

conda activate [your_env]
  1. Install Python packages:
pip install -r requirements.txt
  1. Install essentia following the basic instructions and adding --prefix=$VIRTUAL_ENV in waf configure command:
    1. Check if VIRTUAL_ENV exists and the path is well defined, otherwise you should edit it echo $VIRTUAL_ENV
    2. Install Essentia dependencies.
    3. Compile Essentia for Python3:
      1. python3 ./waf configure --build-static --with-python --with-cpptests --with-examples --with-vamp --prefix=$VIRTUAL_ENV
      2. python3 ./waf
      3. python3 ./waf install

@zseramnay
Copy link

Thanks xaviliz, I will try asap..
Best

Yan

@JoelPerezBermudez04
Copy link

Hi!
I'm trying to install essentia on mac in anaconda (spyder). I have followed @fmiramar noobs step by step guide but when I try to import essentia in my code I get an error that says "No module named 'essentia' "

Thanks,
Joel

PS: Very urgernt

@xaviliz
Copy link

xaviliz commented Nov 29, 2021

I have never tried in conda on Mac OS but I would try the steps in my last comment https://gist.github.com/jarmitage/40e3b7962b0a77a233b2d590d69378d6#gistcomment-3802703
Otherwise you can use venv as suggested.

Best,

@kehuantiantang
Copy link

kehuantiantang commented Mar 11, 2022

You can also create a link from /usr/local/lib/python3.7/site-packages/ to env/lib/python3.7/site-packages, if you create the soft-link, it is no necessary to import sys.path.append('/usr/local/lib/python3.7/site-packages/') and avoid library version conflict.
I face some problems when install by brew

PermissionError: [Errno 1] Operation not permitted: '/usr/local/Cellar/glib/2.70.4/lib/libglib-2.0.0.dylib'
Installing glib/libglib-2.0.0.dylib to /usr/local/Cellar/glib/2.70.4/lib

brew automatically update some depencey library glib2.7.0 and it require OS >= 10.15 (Catalina).

So, I try to build from source, and successfully build it.

git clone https://github.com/MTG/essentia.git
cd ./essentia
# install python3.7 in your mackbook
brew install [email protected]

brew install libffi
ln -s libffi.8.dylib libffi.7.dylib

# add dependency library 
cd /usr/local/Cellar/[email protected]/3.7.12_1/bin

alias pi=/usr/local/Cellar/[email protected]/3.7.12_1/bin/pip3
alias py=/usr/local/Cellar/[email protected]/3.7.12_1/bin/python3

pi install numpy tensorflow

# https://essentia.upf.edu/installing.html
py waf configure  --with-python --with-tensorflow
py waf

# root, install in /usr/local/lib/python3.7/site-packages
sudo py waf install 
ln -s /usr/local/lib/python3.7/site-packages/essentia ${your virtual python path}/lib/python3.7/site-packages/essentia

python usage

import essentia

@CarlosCancino-Chacon
Copy link

Thanks @kehuantiantang! Your answer did the trick.

Just a minor correction: it is necessary to run py waf configure --with-python --with-tensorflow from essentia's root folder

# Go back to essentia
cd path/to/essentia

# https://essentia.upf.edu/installing.html
py waf configure  --with-python --with-tensorflow

Also, you need to make sure to install all of the dependencies with homebrew before installing essentia (or at least before running py waf configure):

brew install eigen libyaml fftw ffmpeg libsamplerate libtag tensorflow

Hope this helps!

Best,

Carlos

@francescopapaleo
Copy link

francescopapaleo commented Nov 28, 2022

Since my trials to install essentia failed many times with Homebrew, I tried to find an installation process using macports.
I run this on a Mid-2015 Mac Book Pro with Mac OSX 10.15 Catalina, it worked also on 10.13 High Sierra.

Please be aware that these operations can compromise your previous working environments or projects, so be aware and make a backup before even starting this step-by-step.
That said, I hope it will be useful to others.

  1. install Mac Ports as explained in the doc and Xcode Command Line Tool

     xcode-select --install
    
  2. install the required port packages:

     sudo port install pkgconfig gcc12 readline sqlite3 gdbm freetype libpng 
     sudo port install eigen3 libyaml libsamplerate libtagedit fftw-3-single
     sudo port install chromaprint
    

chromaprint dependencies include python 3.10 (as of november 2022)

  1. at the end of the installation run one or both:

     sudo port select --set python python310
     sudo port select --set python3 python310
    
  2. create a virtual environment and activate it:

     python3 -m venv env
     source env/bin/activate
    
  3. make sure you have activated the virtual environment and install python packages necessaries for essentia,

     pip install ipython numpy matplotlib pyyaml
    
  4. download essentia source code with git

     git clone https://github.com/MTG/essentia.git
    

read the essentia doc on how to configure, build and install.

  1. Normally the variable VIRTUAL_ENV has been created during virtualenv installation, just in case, you can check it:

     echo $VIRTUAL_ENV
    
  2. then you can start configuring:

     python3 ./waf configure --build-static --with-python --with-cpptests --with-examples --with-vamp --prefix=$VIRTUAL_ENV
    

here is the waf doc if you need any further informations and you can check this post from @xaviliz about this procedure into a virtual environment.

  1. Build

     python3 ./waf
    
  2. Install

    python3 ./waf install
    

if everything goes well you will see this beautiful message:

'Waf: Leaving directory `~/src/essentia/build'
'install' finished successfully (1.757s)

with these steps essentia has been installated in env/lib/python3.10/site-packages/essentia/ I don't know how to change this during the installation process without compromising it. If anyone has suggestions ...

  1. once the installation is over you can test essentia in ipython
import essentia
import essentia.standard
print(dir(essentia.standard))

the output should be

['AfterMaxToBeforeMaxEnergyRatio', 'AllPass', 'AudioLoader', 'AudioOnsetsMarker', 'AudioWriter', 'AutoCorrelation', 'BFCC', 'BPF', 'BandPass', 'BandReject', 'BarkBands', 'BeatTrackerDegara', 'BeatTrackerMultiFeature', 'Beatogram', 'BeatsLoudness', 'BinaryOperator', 'BinaryOperatorStream', [...]

@BenjaminOlsen
Copy link

BenjaminOlsen commented Dec 3, 2022

I had trouble with the ffmpeg libraries (libavcodec, libavformat, etc) installed via brew or ports, so i downloaded the ffmpeg 4.1 source directly from: https://git.ffmpeg.org/gitweb/ffmpeg.git/shortlog/refs/heads/release/4.1, (the most recent snapshot, commit a8a208b), then configured and build ffmpeg with shared libraries:

cd ffmpeg-a8a208b
./configure --enable-shared    
make    
make install

Then following francesco's steps above worked

Edit: I am on osx 10.15.7

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