How to manage multiple Julia projects on the same computer

Hi!

I got the following error message while preparing for a new Julia (v. 1.8.5) project,

MicMac3 ~/Projects/MISR/MISR_Tools % ls
JMTools_template.jl
MicMac3 ~/Projects/MISR/MISR_Tools % julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using PkgTemplates
WARNING: using PkgTemplates.Documenter in module Main conflicts with an existing identifier.

julia> 

Note that I have not (yet) asked to use Documenter in this context, though this plugin had been used to define an earlier project on the same computer, in a different directory. This is a new activity, in a separate (mostly empty) directory. Is there a potential for interference between different projects? If so, how can I keep those projects separated? Can I simply ignore this error message and proceed further?

Thanks for your help in this matter.

I created a new directory, launched Julia and added

Typically one invokes julia --project=. to designate separate projects and thus different packages. It helps avoid these undesirable interactions.

julia --project=. will invoke the project in the actual directory. More generally, I did some writeup on how to organize a Julia project.

Since Julia 1.7, you also can have “shared projects” via julia --project=@myproject .

For instance, when I use pluto, I have a shared environment for Pluto, and when using it, I start Julia with julia --project=@pluto. Note that Pluto notebooks by default automatically will activate their own environments on startup.

2 Likes

Thanks @cmarcotte and @j-fu for your comments. I do understand that I can call Julia to activate a particular project. My question is a bit different, because I do not have a new project yet: I just issued the command using PkgTemplates in a virgin directory with the intent of creating a new project, and thus was surprised to get this warning message. Does it matter? Can I ignore it?

When you type “using xxx.jl” in a new directory, you are still using the global environment, you aren’t creating a new project in that empty directory.
For that you need first to type ] and then activate .
This will tell julia that you want to use (or inialise) a project in that specific directory.

3 Likes

You can do that in a temporary environment, so to avoid installing PkgTemplates (or whatever other tool) in the main environment, to avoid those name clashes in the future.

What I don’t understand is why there is a name clash if the first thing in the session is loading PkgTemplates. Do you have something in your ~/.julia/config/startup.jl loading another package?

2 Likes

@sylvaticus: Thanks for this clarification: I did not know there was a difference between using [package name] and ] followed by activate . and add [package name]… Always happy to learn!

@lmiq: Thanks for this intriguing suggestion: I’ll have to learn about temporary environment

@aramirezreyes: Indeed, I found that my file ~/.julia/config/startup.jl already contained the instruction using Documenter, most probably as a result of a prior project. I have commented out that line, and the project creation process moves ahead further, but now generates a different error message when I attempt to use the template:

julia> tmpl("JMTools")
[ Info: Running prehooks
[ Info: Running hooks
  Activating new project at `~/Projects/MISR/MISR_Tools/JMTools/test`
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `~/Projects/MISR/MISR_Tools/JMTools/test/Project.toml`
  [8dfed614] + Test
    Updating `~/Projects/MISR/MISR_Tools/JMTools/test/Manifest.toml`
  [2a0f44e3] + Base64
  [b77e0a4c] + InteractiveUtils
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [8dfed614] + Test
  Activating project at `~/.julia/environments/v1.8`
ERROR: SystemError: opening file "~/Projects/MISR/MISR_RCCM/JMRCCM/docs/make.jl": No such file or directory
Stacktrace:
  [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
    @ Base ./error.jl:176
  [2] #systemerror#80
    @ ./error.jl:175 [inlined]
  [3] systemerror
    @ ./error.jl:175 [inlined]
  [4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
    @ Base ./iostream.jl:293
  [5] open
    @ ./iostream.jl:275 [inlined]
  [6] open(f::Base.var"#387#388"{String}, args::String; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:382
  [7] open
    @ ./io.jl:381 [inlined]
  [8] read
    @ ./io.jl:462 [inlined]
  [9] render_file
    @ ~/.julia/packages/PkgTemplates/RTfWa/src/plugin.jl:326 [inlined]
 [10] hook(p::Documenter{GitHubActions}, t::Template, pkg_dir::String)
    @ PkgTemplates ~/.julia/packages/PkgTemplates/RTfWa/src/plugins/documenter.jl:188
 [11] (::PkgTemplates.var"#17#20"{typeof(PkgTemplates.hook), Template, String})(p::Documenter{GitHubActions})
    @ PkgTemplates ~/.julia/packages/PkgTemplates/RTfWa/src/template.jl:132
 [12] foreach(f::PkgTemplates.var"#17#20"{typeof(PkgTemplates.hook), Template, String}, itr::Vector{PkgTemplates.Plugin})
    @ Base ./abstractarray.jl:2774
 [13] (::PkgTemplates.var"#16#19"{Template, String})(h::typeof(PkgTemplates.hook))
    @ PkgTemplates ~/.julia/packages/PkgTemplates/RTfWa/src/template.jl:131
 [14] (::Base.var"#57#58"{PkgTemplates.var"#16#19"{Template, String}})(#unused#::Nothing, x::Function)
    @ Base ./tuple.jl:555
 [15] BottomRF
    @ ./reduce.jl:81 [inlined]
 [16] afoldl
    @ ./operators.jl:549 [inlined]
 [17] _foldl_impl
    @ ./tuple.jl:277 [inlined]
 [18] foldl_impl
    @ ./reduce.jl:48 [inlined]
 [19] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
 [20] #mapfoldl#259
    @ ./reduce.jl:170 [inlined]
 [21] #foldl#260
    @ ./reduce.jl:193 [inlined]
 [22] foreach
    @ ./tuple.jl:555 [inlined]
 [23] (::Template)(pkg::String)
    @ PkgTemplates ~/.julia/packages/PkgTemplates/RTfWa/src/template.jl:129
 [24] top-level scope
    @ REPL[2]:1

It looks like Julia complains about the absence of the file ~/Projects/MISR/MISR_RCCM/JMRCCM/docs/make.jl, which sounds strange to me because it is precisely the purpose of the PkgTemplates package and the template file to create and setup the project as needed. Indeed, if I manually create the JMRCCM directory, then the process does not proceed at all because that subdirectory already exists.

Thanks for any further suggestion about this issue.

1 Like

Update: Sorry for the confusion: I just realized that my use of the template file was inconsistent because it requested the creation of the JMTools project but was still referring to the JMRCCM subdirectory in the Documenter section. Thanks again to all for your inputs.

2 Likes