I'm writing a Python IDE and I want to let user to choose the interpreter for executing the program.
Just do it like other IDEs then and simply supply a dialog where users can add interpreters they want to be able to run the code with.
Eclipse does this for example for Java Runtimes, and it’s perfectly fine to have it like that. Especially for languages like Python where virtual environments are an important thing which each have their own exectutable.
You certainly can come up with a one-time detection that checks some common locations. For Windows, this would obviously be the registry, as the py.exe
launcher requires the interpreters to be registered there—at least the system-wide ones. On Unix machines, you could check the common bin/
folders, most prominently /usr/local/bin/
which is the standard location where Python installs itself. You could also check the PATH for Python executables. But all those things should be considered carefully and only offer an initial setup. There are always edge cases where a user didn’t do the “standard thing” where your detection will fail. For example I don’t have my Python interpreters in my path, and a linux server I access I have installed Python into a non-standard folder in my home directory. And finally, just because it looks like Python doesn’t mean it is Python.
Yes, you can do some guesswork to come up with an initial set of interpreters, but really don’t spend too much time on it. In the end, you won’t be able to detect everything perfectly anyway. And you will miss virtual environments—which might be very crucial to the project the user is working on in your IDE.
So instead of wasting time on bad detection, spend more time on creating a manual dialog to register interpreters. You will need that anyway, and a good interface can make it very easy—even for beginners—to use it.
os.walk()
but this will be very slow if you aren't clever in figuring out where to search – Rootstockwhich
, and have a dig around in ~/.virtualenvs. A command likefind / -name "python" 2> /dev/null
will find files named python, which may or may not be python interpreters. Any way you do this, you are going to have to let the user specify their own, with a dialog. – Cycad