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.

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is works, thanks. I'm looking for something like this.
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")

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.