1

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. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
tmsblgh
  • 517
  • 5
  • 21

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
  • 306
  • 2
  • 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
  • 17,084
  • 9
  • 43
  • 67
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
  • 11