0

How can I check that clang is built or that clang tool is available?

I need to check it in Python 2.7.

I tried with os.path.exists(file_path), but you can build clang anywhere so it is not the best way.

n. 1.8e9-where's-my-share m.
  • 102,958
  • 14
  • 123
  • 225
tmsblgh
  • 487
  • 5
  • 19

3 Answers3

2

This might work for you if clang is available in the path, it performs a search for the presence of the clang executable:

from distutils.spawn import find_executable

clang_executable = find_executable('clang')

If it finds clang it will return the path to the executable, e.g. /usr/bin/clang, otherwise it will return None.

This is the relevant part of the docs (not that descriptive), and here is a SO question looking for something similar.

Community
  • 1
  • 1
Apoc
  • 196
  • 1
  • 6
1

You could install gnu which: http://gnuwin32.sourceforge.net/packages/which.htm

Add which to your PATH, and then run:

import subprocess
subprocess.check_output("which clang")
twasbrillig
  • 14,704
  • 9
  • 39
  • 61
1

If you're using Unix/Linux and clang is on your PATH:

import subprocess
c = subprocess.call(["which", "clang"])
if c == 0:
    print("clang is available")
Pold
  • 337
  • 1
  • 10