Confused about package management

Hi. Sorry this question might seem confused because I’m confused.

I’ve been working with a local package with no problems. Sounds good, but today I was going to set up a new project and I thought I’d use PkgTemplates as suggested in the docs. This lead to a surprise that I’m confused about. Below, I’ve got a shell dialog. I start by going into my current project, get into Pkg and get status - everything ok. I go one level up in directory from that project where I want to set up my new project, go into pkg to add PkgTemplates and there’s an error reported with my other package that I don’t understand. My understanding of packages (please correct me if I’m wrong) is that when I’m in the directory of a package and use ‘julia --project’ that I’m now in that package’s environment. Then, likewise, if I’m not in a package I’m using the global environment.

Does this error imply that I set the AZ_Reversi.jl package up incorrectly? If so, how do I correct it? If not, how do I proceed in adding PkgTemplate?

bill@Williams-Air src % pwd
bill@Williams-Air src % cd AZ_Reversi.jl 
bill@Williams-Air AZ_Reversi.jl % pwd
bill@Williams-Air AZ_Reversi.jl % julia --project
... startup stuff removed ...
(AZ_Reversi) pkg> status
Project AZ_Reversi v0.1.0
Status `~/src/AZ_Reversi.jl/Project.toml`
  [8ed9eb0b] AlphaZero v0.5.4
  [c7e460c6] ArgParse v1.1.4
  [a8cc5b0e] Crayons v4.1.1
  [cd3eb016] HTTP v1.9.14
  [4138dd39] JLD v0.13.3
  [df9a0d86] Oxygen v1.1.11
  [295af30f] Revise v3.5.3
⌃ [90137ffa] StaticArrays v1.5.26
  [1b6eb727] SwaggerMarkdown v0.2.1
  [ddb6d928] YAML v0.4.9
  [cf7118a7] UUIDs
Info Packages marked with ⌃ have new versions available and may be upgradable.

(AZ_Reversi) pkg> ^C

bill@Williams-Air AZ_Reversi.jl % cd ..
bill@Williams-Air src % julia --project
... startup stuff removed ...
(@v1.9) pkg> status
Status `~/.julia/environments/v1.9/Project.toml`
→ [479812a0] AZReversi v0.1.0 `../../../src/AZReversi`
→ [197bbe58] AZ_Reversi v0.1.0 `../../../src/AZ_Reversi`
  [8ed9eb0b] AlphaZero v0.5.4 `~/src/AlphaZero.jl`
  [a8cc5b0e] Crayons v4.1.1
⌃ [a93c6f00] DataFrames v1.5.0
⌃ [c3e4b0f8] Pluto v0.19.25
  [295af30f] Revise v3.5.3
⌃ [90137ffa] StaticArrays v1.5.26
Info Packages marked with → are not downloaded, use `instantiate` to download
Info Packages marked with ⌃ have new versions available and may be upgradable.

One other clue is in ~/.julia/environments/v1.9/Manifest.toml:

deps = ["AlphaZero"]
path = "../../../src/AZReversi"
uuid = "479812a0-3da7-4be1-b6d2-59909e2c68c0"
version = "0.1.0"

deps = ["AlphaZero", "Crayons", "StaticArrays"]
path = "../../../src/AZ_Reversi"
uuid = "197bbe58-db13-46b8-9db2-48c8d20fa952"
version = "0.1.0"

Generally what I do is to create a new package with PkgTemplates, and then copy the source files of the “project” into the /src directory of the new package. A package is something a little more complex than a project. A project is just a directory with a Manifest.toml and a Project.toml files. A package has a specific directory structure and a main file name called “MyProject.jl” in the ‘src’ directory.

If you want very simple instructions on how to create a new “package”, check this: Create new package · JuliaNotes.jl.

I would not mix those steps with your current project directory structure. Just copy what you need after the package has been created.

1 Like

Thanks. That advice makes sense. However, I still have a problem in that outside of the context of my AZ_Reversi.jl project, I can’t install PkgTemplates.

Considering my ~/.julia/environments/v1.9/Manifest.toml, would it make sense to edit that file by hand and remove the AZReversi records (since it doesn’t exist at all), and change the path of the AZ_Reversi records to be the absolute path instead of the relative path that it’s got? I know the file says not to edit it at the top, but these seem like easy enough edits to do.

I think you are better off removing these erroneous entries. No need for editing a file hand though. Simple open a REPL with the global environment, go to pkg mode by typing “]” and then remove them with rm AZReversi AZ_Reversi :slight_smile:

If you ever edit a Manifest.toml, after you should activate the project and do a do a resolve (in pkg mode) to ensure consistency.

Thanks. Makes sense.

It is likely better to just remove everything from your global environment, leaving there only packages that are routinely used for development (like Revise, for example).

For example, when using PkgTemplates, it is actually better to just start a temporary environment and install and use it there, so it does not clutter your default environment. Thus, use

julia> ] activate --temp 

(jl_ML0bEf) pkg> add PkgTemplates

julia> using PkgTemplates # and etc

Got it. Thanks!