I’ve been trying to follow the steps here:
I am testing from the REPL. Basically I follow the steps and I see that I make a new project, which puts Pkg in the “MyProject” enviroment:
But when I backspace out, this “MyProject” goes away infront of the Julia part. How can I be sure that the next packages I install are actually installed in this enviroment?
You can use
Base.active_project(). It will return the address of the
Project.toml used for the
Pkg. Another similar method exist,
Base.currect_project(), but the “current” there refers to the first
Project.toml you find searching up from your current location
pwd(), not the one used by the
They can match or not.
Example: Opening a
julia section in my home directory.
julia> # Press ]
(@v1.5) pkg> # At first, my global envitoment is activated
# Returns nothing (or empty string, I don't know)
# This is because in my home folder (and parents), no Project.toml exist.
# This time, the active global Project.toml is returned
# If I navigate to its container folder now both methods returns the same
julia> Base.current_project() == Base.active_project()
Okay, so I suppose, that I should always use “Base.active_project()”, since it will inform me in which enviroment any Pkg install will be saved in?
Okay nice, will mark your first answer is solution, thanks!
For interactive use I don’t think you need to do anything: if
pkg> says you are in MyProject, that’s where packages will be installed. For a programmatic check however you need @josePereiro’s solution.