tmsblgh
tmsblgh

Reputation: 527

How to check for clang presence in Python?

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.

Upvotes: 1

Views: 735

Answers (3)

Pold
Pold

Reputation: 347

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")

Upvotes: 1

twasbrillig
twasbrillig

Reputation: 18891

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")

Upvotes: 1

Apoc
Apoc

Reputation: 306

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.

Upvotes: 2

Related Questions