How to Install LLVM-10 on Ubuntu 18.04

pythonsoftware installation

There are some earlier questions, most notably this, but they didn't help me. I am trying to install llvm version 10 (or 9) because it is a dependency for the pyod Python package. When trying to install, I get this error:

(.venv) user@desktop:/media/Projects/outliers$ pip install llvmlite
Collecting llvmlite
  Using cached https://files.pythonhosted.org/packages/0b/96/07bfa93a103fb9e3e9ae7f9f7c6687ae714aee66b6f3000da3fad71e0aa2/llvmlite-0.34.0.tar.gz
Building wheels for collected packages: llvmlite
  Running setup.py bdist_wheel for llvmlite ... error
  Complete output from command /media/Projects/outliers/.venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-a4jzbt70/llvmlite/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpzu8welrdpip-wheel- --python-tag cp36:
  running bdist_wheel
  /media/Projects/outliers/.venv/bin/python3 /tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py
  LLVM version... 6.0.0
  
  Traceback (most recent call last):
    File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 191, in <module>
      main()
    File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 181, in main
      main_posix('linux', '.so')
    File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 143, in main_posix
      raise RuntimeError(msg)
  RuntimeError: Building llvmlite requires LLVM 10.0.x or 9.0.x, got '6.0.0'. Be sure to set LLVM_CONFIG to the right executable path.
  Read the documentation at http://llvmlite.pydata.org/ for more information about building llvmlite.
  
  error: command '/media/Projects/outliers/.venv/bin/python3' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for llvmlite
  Running setup.py clean for llvmlite
Failed to build llvmlite
Installing collected packages: llvmlite
  Running setup.py install for llvmlite ... error
    Complete output from command /media/Projects/outliers/.venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-a4jzbt70/llvmlite/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-xelmdsmd-record/install-record.txt --single-version-externally-managed --compile --install-headers /media/Projects/outliers/.venv/include/site/python3.6/llvmlite:
    running install
    running build
    got version from file /tmp/pip-build-a4jzbt70/llvmlite/llvmlite/_version.py {'version': '0.34.0', 'full': 'c5889c9e98c6b19d5d85ebdd982d64a03931f8e2'}
    running build_ext
    /media/Projects/outliers/.venv/bin/python3 /tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py
    LLVM version... 6.0.0
    
    Traceback (most recent call last):
      File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 191, in <module>
        main()
      File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 181, in main
        main_posix('linux', '.so')
      File "/tmp/pip-build-a4jzbt70/llvmlite/ffi/build.py", line 143, in main_posix
        raise RuntimeError(msg)
    RuntimeError: Building llvmlite requires LLVM 10.0.x or 9.0.x, got '6.0.0'. Be sure to set LLVM_CONFIG to the right executable path.
    Read the documentation at http://llvmlite.pydata.org/ for more information about building llvmlite.
    
    error: command '/media/Projects/outliers/.venv/bin/python3' failed with exit status 1
    
    ----------------------------------------
Command "/media/Projects/outliers/.venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-a4jzbt70/llvmlite/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-xelmdsmd-record/install-record.txt --single-version-externally-managed --compile --install-headers /media/Projects/outliers/.venv/include/site/python3.6/llvmlite" failed with error code 1 in /tmp/pip-build-a4jzbt70/llvmlite/

I believe the most important line is this:

RuntimeError: Building llvmlite requires LLVM 10.0.x or 9.0.x, got '6.0.0'. Be sure to set LLVM_CONFIG to the right executable path.

If one tries to update it, it says 6.X is the newest:

user@desktop:~$ apt install llvm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
llvm is already the newest version (1:6.0-41~exp5~ubuntu1).
The following packages were automatically installed and are no longer required:
  boinc-client golang-1.10-go golang-1.10-src golang-src libboinc7 libgsoap-2.8.60 libllvm10 libllvm10:i386 libnvidia-cfg1-440 libnvidia-common-435 libnvidia-common-440
  libnvidia-compute-440 libnvidia-decode-440 libnvidia-ifr1-440 libvncserver1 linux-headers-4.15.0-106 linux-headers-4.15.0-106-generic linux-headers-4.15.0-115
  linux-headers-4.15.0-115-generic linux-headers-5.4.0-45-generic linux-hwe-5.4-headers-5.4.0-45 python-fasteners python-monotonic python-pexpect python-ptyprocess
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.

I have also tried 1) using their apt deb sources (didn't work, nothing happens when added, latest version is still 6.X when using apt upgrade), and 2) downloading their files (no instructions given how to install).

Best Answer

I am on Mint 19.3, but this should also work for Ubuntu 18.04, which is what this Mint version is based on.

My solution was to specify the version to use specifically when installing:

sudo apt-get install llvm-10*

The reason to use the glob asterisk here is that some of the related packages are also needed for things to work, so merely installing the base package will not work (at least, not for pyod which when you try pip install gives you llvm-config: error: component libraries and shared library). This follow-up problem and solution was mentioned here.

After this, you need to change the llvm-config link because otherwise it still points to the 6.X version. This is done by (from here):

sudo -i
cd /usr/bin
rm llvm-config #if it exists already, which probably it does
ln -s llvm-config-10 llvm-config

The config now points to the correct version. Installing the 10 version does not update this pointer. After this, my pip command worked (i.e. pip install llvmlite, and after that, pip install pyod).

Related Question