How to programmatically identify the currently active environment?

When in Pkg mode, the prompt shows the name of the currently active environment. I would like to obtain this information programmatically. As far as I can tell, Pkg doesn’t document any way to do this.

From poking around in the source code I figured out that Pkg.Types.Context().env.pkg.name will return the name of the currently active package. But it doesn’t work if the environment is just the main Julia environement instead of a package.

Is there a better way to programmatically identify the currently active environment?

Maybe try Base.active_project()

2 Likes

That seems to work. Thanks