From Julia Doc - 5. Creating Package - Pkg not found after Activating?

Sometimes I generate a pkg, then activate, then import and it works fine. Other times I get the msg - pkg not found and it’s right there in the directory I’m in. It’s such a simple process, I don’t understand what’s changing. Do I need to instantiate each time? Also, if I install a package - ie - Plots or IJulia, they go into ‘packages’ folder in .julia - yet when I create a HelloWorld pkg to learn the process, I’m just choosing my home folder to create the project in. Is this maybe a local / global environment issue? I used snap to install julia – classic (Linux Mint) - maybe that’s interfering?

See Revise.jl

Lost interest . . .

Try the following method (you can ignore Revise.jl for now). Since you use Linux, create project in your home directory (if necessary - type semicolon for shell> to check which directory you’re in) - also pkg>status is useful.

Creating a Pkg – Julia

julia>

(@v1.9) pkg> generate HelloWorld
Generating project HelloWorld: HelloWorld/Project.toml
HelloWorld/src/HelloWorld.jl

(@v1.9) pkg> activate . Activating project at ~

julia> using Revise

(HelloWorld) pkg> status
Project HelloWorld v0.1.0
Status ~/HelloWorld/Project.toml (empty project)

(HelloWorld) pkg> switch to Julia REPL

julia> include(“HelloWorld/src/HelloWorld.jl”)

julia> HelloWorld.greet() Hello World! Julia>

(Edit: You should be able to use: pkg> activate ./HelloWorld and then import HelloWorld and have it work. If it doesn’t precompile, try the above method.)

1 Like

Thanks - it worked. Instead of just ( activate . ) I was using activate ~./HelloWorld, which should work, but I’d get an error msg that it couldn’t find the pkg. Also, I was adding ‘using HelloWorld’ in there which I guess is unnecessary and seemed to cause the same problem. Thanks again.

I think part of the problem is typing

activate ~./HelloWorld

Julia won’t understand ~, which is something that would be interpreted by a (Unix/Linux) shell. Julia is clever, but not that clever.

(It might be a copy/paste mistake, but even if Julia understood ~, you probably mean ~/HelloWorld, not ~./HelloWorld)

1 Like

@magister-ludi
And it’s an easy mistake to make -

from the Julia documentation:
We can now activate the project by using the path to the directory where it is installed, and load the package:

pkg> activate ./HelloWorld

A Linux user is always using that tilde. (~/) is the beginning of a path to a file or directory below the user’s home directory. If you’re creating the new Julia pkg in your home directory, it’s easy to mix the two syntaxes and mistakenly type that tilde on the front - though it doesn’t belong there.

I almost never put things in the home directory. I have a ~/Repos directory that I put anything development related.

One other thing to note is that, while the pkg repl understands the ~ shortcut, actual code will not. You’d need to do expanduser("~/")

1 Like

You’re right, of course - It makes sense to create a new directory for storing real pkgs that are going to be used and developed. In my case, I’m just learning the commands for this pkg build process as part of learning Julia. Since my terminal always wakes in home directory, it just saves me a step.

1 Like