I am writing a Python IDE, and I want the user to be able to choose an interpreter to execute the program.
Just do it, like other IDEs, and just put a dialog box in which users can add interpreters with which they can run code.
Eclipse does this, for example, for Java Runtimes, and is perfectly fine to do so. Especially for languages ββlike Python, where virtual environments are an important thing, each of which has its own exectutable.
You can certainly come up with a one-time discovery that checks for some common locations. For Windows, this will obviously be a registry, since the py.exe launcher requires translators to be registered there - at least system-wide. On Unix machines, you can check the bin/ shared folders, most notably /usr/local/bin/ , which is the standard place where Python installs itself. You can also check PATH for Python executables. But all these things should be carefully considered and only initial setup should be offered. There are always extreme cases where the user has not done the βstandard thingβ where your discovery will fail. For example, I do not have my Python interpreters in my path, and I am accessing a Linux server. I installed Python in a non-standard folder in my home directory. And finally, just because it looks like Python does not mean that it is Python.
Yes, you can make some guesses to come up with the original set of interpreters, but don't really waste too much time on it. In the end, you cannot fully discover everything. And you will miss virtual environments that can be very important for a project that a user is working on in your IDE.
Therefore, instead of wasting time on poor detection, spend more time creating a manual dialogue for registering interpreters. In any case, you will need it, and a good interface can make it very simple - even for beginners - to use it.
source share