# Pkg behavior that confused me

**URL:** <https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453>\
**Category:** General Usage\
**Created:** [August 28, 2022, 7:54am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453 "2022-08-28T07:54:48Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 28, 2022, 7:54am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/1 "2022-08-28T07:54:48Z")

</div>

Hello all

I spent a long time chasing something very confusing to me in Pkg.

when I run our code on the command line as we always do, it seems to run

```julia
julia -e 'push!(LOAD_PATH,"Zinstrument/");using Zinstrument;ProcessDatabase()'

```

but runs with a old version of the code

when I do the same in the repl

```julia
push!(LOAD_PATH,"Zinstrument")
4-element Vector{String}:
 "@"
 "@v#.#"
 "@stdlib"
 "Zinstrument"

julia> using Zinstrument
[Info: Precompiling Zinstrument [d6e76910-d7cc-43bf-969a-b976b4bc5f70]
WARNING: using Zinstrument.Zinstrument in module Main conflicts with an existing identifier.
ERROR: importing Zinstrument into Main conflicts with an existing identifier

```

The repl ERROR behavior seems correct, but is the command line also correct?

sorry for the confusion

best, Jack

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 28, 2022, 10:44am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/2 "2022-08-28T10:44:01Z")

</div>

Maybe it gets picked up from one of the earlier environments. Try `pushfirst!` instead maybe.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 28, 2022, 3:02pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/3 "2022-08-28T15:02:49Z")

</div>

Thanks @kristoffer.carlsson

yes, can be solved, but it is concerning to us that one can end up running different code depending on whether one uses the repl or command line in exactly the same way.

and this took us hours to diagnose as all was correct in the development (repl) and not in production runs (command line), on julia 1.8.

all the best, jack

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [August 28, 2022, 3:49pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/4 "2022-08-28T15:49:08Z")

</div>

Is the REPL the plain Julia REPL started from a terminal. Or is it inside VS Code or Juno? Those IDEs might automatically activate the current project enviroment e.g. the equivalent of `julia --project=.`

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [August 28, 2022, 3:52pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/5 "2022-08-28T15:52:13Z")

</div>

> [@JackStrauss](#):
>
> ```julia
> push!(LOAD_PATH,"Zinstrument")
> 
> ```

I do believe changing the `LOAD_PATH` is not considered good practice, and it is not suggested anywhere in the documentation (correct me if I am wrong). So I would recommend steering away from it.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 28, 2022, 3:55pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/6 "2022-08-28T15:55:59Z")

</div>

> [@SteffenPL](#):
>
> Is the REPL the plain Julia REPL started from a terminal. Or is it inside VS Code or Juno? Those IDEs might automatically activate the current project enviroment e.g. the equivalent of `julia --project=.`

in this specific case, directly from the terminal.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 28, 2022, 4:06pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/7 "2022-08-28T16:06:50Z")

</div>

> [@Henrique\_Becker](#):
>
> I do believe changing the `LOAD_PATH` is not considered good practice, and it is not suggested anywhere in the documentation (correct me if I am wrong). So I would recommend steering away from it.

Thanks. So a weird corner case we should not have found. Fair enough. We will search and eliminate.

I forget what brought us to that solution, but reason was because we never understood how Pkg worked and all our code lives in a shared drive and run on different julia versions and op systems. We have moved away from using Pkg to just modules but this was a leftover.

thanks a lot for all the clarifications

best, jack

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 28, 2022, 9:15pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/8 "2022-08-28T21:15:46Z")

</div>

> [@JackStrauss](#):
>
> We have moved away from using Pkg

Not a good idea. You should always use project specific environments, and for these you need Pkg…

And if there is something you do not understand just ask…

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [August 28, 2022, 9:40pm UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/9 "2022-08-28T21:40:12Z")

</div>

I highly recommend using `Pkg.develop` to load code from a local path. You are creating an ad hoc environment stack.

Now there seems to be several issues here;

1. What is the current active environment of the REPL versus the script? Do you use the `--project` option in either case or do you attempt to `Pkg.activate` anything? Is the environment variable `JULIA_PROJECT` define? What is the output of `pkg"status"` in the REPL? What is the output of `InteractiveUtils.versioninfo()` in the REPL?

2. There seems to be a module called `Zinstrument` that contains another module called `Zinstrument`. This seems odd. Could you tell us more about how code is structured. What are the relative paths of files called `Zinstrument.jl`? How do you use `include`, `using`, and `import`?

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 6:13am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/10 "2022-08-29T06:13:55Z")

</div>

> [@mkitti](#):
>
> - What is the current active environment of the REPL versus the script? Do you use the `--project` option in either case or do you attempt to `Pkg.activate` anything? Is the environment variable `JULIA_PROJECT` define? What is the output of `pkg"status"` in the REPL? What is the output of `InteractiveUtils.versioninfo()` in the REPL?

We don’t use --project. JULIA\_PROJECT is not defined

julia\> Pkg.status()  
Status `~/.julia/environments/v1.8/Project.toml`  
[fbe9abb3] AWS v1.76.1  
[336ed68f] CSV v0.10.4  
[a93c6f00] DataFrames v1.3.4  
[31c24e10] Distributions v0.25.68  
[59287772] Formatting v0.4.2  
[c27321d9] Glob v1.3.0  
[682c06a0] JSON v0.21.3  
[bdcacae8] LoopVectorization v0.12.124  
[e1d29d7a] Missings v1.0.2  
[d9ec5142] NamedTupleTools v0.14.1  
[429524aa] Optim v1.7.2  
[d96e819e] Parameters v0.12.3  
[626c502c] Parquet v0.8.4  
[92933f4c] ProgressMeter v1.7.2  
[6f49c342] RCall v0.13.13  
[295af30f] Revise v3.4.0  
[276daf66] SpecialFunctions v2.1.7  
⌃ [9e3dc215] TimeSeries v0.14.0  
Info Packages marked with ⌃ have new versions available

InteractiveUtils.versioninfo()  
Julia Version 1.8.0  
Commit 5544a0fab76 (2022-08-17 13:38 UTC)  
Platform Info:  
OS: macOS (arm64-apple-darwin21.3.0)  
CPU: 8 × Apple M1  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)  
Threads: 1 on 4 virtual cores

> [@mkitti](#):
>
> - There seems to be a module called `Zinstrument` that contains another module called `Zinstrument`. This seems odd. Could you tell us more about how code is structured. What are the relative paths of files called `Zinstrument.jl`? How do you use `include`, `using`, and `import`?

it lives is folder called Zinstrument  
all we do is  
push!(LOAD\_PATH,“Zinstrument”)  
using Zinstrument

Zinstrument: ✗ tree  
.  
├── Zinstrument  
│ ├── Manifest.toml  
│ ├── Project.toml  
│ └── src  
│ ├── Forecast.jl  
│ ├── Functions.jl  
│ ├── MakeZinstrumentFiles.jl  
│ └── Zinstrument.jl

Zinstrument.jl looks like

```julia
module Zinstrument

using Random 
using Distributions 
using DataFrames 
using JSON 
using SpecialFunctions 
using Optim 
using Statistics 
using TimeSeries 
using CSV 
using Parquet
using NamedTupleTools
#using SHA

#using AWS
include("Functions.jl")
include("Forecast.jl")
include("MakeZinstrumentFiles.jl")
end 

```

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 6:55am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/11 "2022-08-29T06:55:46Z")

</div>

> [@ufechner7](#):
>
> Not a good idea. You should always use project specific environments, and for these you need Pkg…
> 
> And if there is something you do not understand just ask…

Thanks @ufechner7

We have shared drive on a zfs with frequent snapshots, all backed up to 2 zfs remote systems. We used to use git, but now the team prefers the simplicity of zsh snapshots, and the added benefit of all data, code, binaries, etc. can be found as it existed at any past date via the simplicity of the .zfs folder. so no git. (yes, git branches would make sense, but team refused). The zfs and rest is managed by IT support not us.

we followed the instructions here, [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/creating-packages/) and that is why we need to use push!(LOAD\_PATH. It says to cd into the folder, but push!(LOAD\_PATH seems to do the same. Except we ended up with the inconsistency between command line and repl (and old code running on command line)

That page says to use templates, [GitHub - JuliaCI/PkgTemplates.jl: Create new Julia packages, the easy way](https://github.com/invenia/PkgTemplates.jl) , and we found the quote on that page " Using [PkgTemplates](https://github.com/invenia/PkgTemplates.jl/) is straightforward." to be interesting. Perhaps simple if code lives on githup, but not else. For us, PkgTemplates.jl is very complicated and hard to understand. [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/creating-packages/) is simpler.

All we want is

- not to use git
- something like the simplicity of R local libraries
- if a package is changed on one system, and tested to work there, it will automatically run on any remote system regardless or operating system or julia version.
- The ability to have “using MyPackage” instead of having to manage paths.
- No change to the environment of the remote system, except to download julia and its packages.
- documentation that someone with a PhD in physical sciences and not computer science will understand. Team does science not coding, except when necessary, and then they will do as little as they get away with. They like simple recipes.

@ufechner7 I know we have special needs and outside of what Julia normally does. Besides packages, Julia is a wonderful language and our code is simpler, faster to run and code, and more reliable than when we used R+Rcpp before. And we have become annoying Julia evangelist in our org.

and thank you all for making such a wonderful language

all the best, Jack

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 29, 2022, 7:34am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/12 "2022-08-29T07:34:20Z")

</div>

Did you try to run julia with the option

```julia
--startup-file=no

```

?  
A startup file might explain the difference between repl and script use…

Otherwise your usage scenario is very special, it will be difficult to get support for this from the open source community…

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 29, 2022, 7:49am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/13 "2022-08-29T07:49:01Z")

</div>

> [@JackStrauss](#):
>
> not to use git

It is very brave to try to do serious SW development in a team without using **git**. I know **git** is not very user friendly, but I think it is worth the effort to learn it if you program more than one hour per week, even if you are a scientist who works on his own…

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 8:00am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/14 "2022-08-29T08:00:10Z")

</div>

> [@ufechner7](#):
>
> ```julia
> --startup-file=no
> 
> ```
> 
> ?  
> A startup file might explain the difference between repl and script use…

Hi

we have no startup files.

sorry for all the trouble, just was confused by different Julia behavior when run in repl and command line. and wanted to know why. but now I know what not to do.

And I appreciate we had a weird case, packages without github.

and in any case, we can make it all run without packages, modules work fine.

all the best, Jack

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 8:10am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/15 "2022-08-29T08:10:25Z")

</div>

> [@ufechner7](#):
>
> It is very brave to try to do serious SW development in a team without using **git**. I know **git** is not very user friendly, but I think it is worth the effort to learn it if you program more than one hour per week, even if you are a scientist who works on his own…

I know, I have used git a lot and know how it works, but when one never makes branches, the advantages of git over alternatives are not so clear. we snapshot our zfs every few minutes. and when we have binary files, and data, need something besides git. Still we use git.

we have several packages, and other code to run things. My understanding of julia packages is that each needs its own git repository, ideally on githup. So does not play nice with all our packages being in same git repository.

and even if one lives by git, there is no reason to keep packages in separate repositories.

So if there was a way to easily use Julia packages without git (I know it can be done, but its not easy), would much prefer that.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 29, 2022, 8:22am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/16 "2022-08-29T08:22:50Z")

</div>

> [@JackStrauss](#):
>
> but now I know what not to do.

Can you share your “lessons learnt” so that others can avoid to make the same mistake?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 29, 2022, 8:29am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/17 "2022-08-29T08:29:07Z")

</div>

> [@JackStrauss](#):
>
> So if there was a way to easily use Julia packages without git (I know it can be done, but its not easy), would much prefer that.

FWIW, there is no need to use git at all for developing packages locally. Pkg has support to directly download a package from an URL using git, but you can just as well download it normally and use `Pkg.develop` to get it into your environment.

The git stuff in Pkg is a feature but it isn’t really required for many things.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 8:51am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/18 "2022-08-29T08:51:22Z")

</div>

> [@ufechner7](#):
>
> Can you share your “lessons learnt” so that others can avoid to make the same mistake?

if it is just my code, I happily use git and julia packages on githup.

for a group of people who are not computer scientists its different (in my world). They complain about all that that is complex and does not bring immediate benefits.

I deal with a team that uses Dropbox history to manage their code. And that is prohibited by our security policy. That got overridden. (I run git on cron without them knowing every 30 min. )

most are happy to keep 100s of source files from all sorts of languages in same folder. see no benefit in multiple folders. most common view in the youngest collegues who use search and not folders.

my collegues love zfs snapshots. automatic, simple, handled by IT.

So when it comes to Julia. They told me point blank. "No packages. No git. unless you pay someone to do it for us. " except the language was not that polite. Modules are a hard sell, but now accepted, sort of. Sellable benefit: no namespace collusions.

so my lesson learned is: lowest common denominator. All help comes from stackoverflow. Don’t expose anybody to compexity that does not bring immediate benefits.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [August 29, 2022, 9:40am UTC](https://discourse.julialang.org/t/pkg-behavior-that-confused-me/86453/19 "2022-08-29T09:40:17Z")

</div>

> [@kristoffer.carlsson](#):
>
> FWIW, there is no need to use git at all for developing packages locally. Pkg has support to directly download a package from an URL using git, but you can just as well download it normally and use `Pkg.develop` to get it into your environment.

Yes, I know it possible and am reading [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/creating-packages/) carefully

thanks for the comments

jack
