Can't install any packages

I’ve been using Julia for six years. I moved to it from Python, but one thing I absolutely cannot do is install packages. So today when I saw a graph in Wolfram Alpha that didn’t look right (eventually I found the root issue seems to be that Wolfram Alpha thinks arcsin(sin(x)/2)) is equal to sin(x)/2) I decided I’d install a graphing calculator program on my computer…except why should I do that when I have Julia?! because I can’t install Plots.

So today is the day I suck it up and ask.

Accord to Plots, you install it with Pkg.add("Plots") which results in
Pkg.add(“Plots”)
ERROR: UndefVarError: Pkg not defined
Stacktrace:
[1] top-level scope at REPL[2]:1

The Julia documentation says to enter the package manager with “]” (okay so far) and enter “add Plots”. That last part failed with “ERROR: no active project” except it most certainly is an active project.

The no active project error refers to the term “project” as it’s used in the Pkg.jl documentation here: 4. Working with Environments · Pkg.jl

I’m not sure how you got into a state where there is no project active in your package manager. What do you get if you run ]status ?

And what version of Julia are you using? Have you done anything to your ~/.julia/config/startup.jl file?

1 Like
pkg> status
ERROR: no active project
$ julia --version
julia version 1.4.2
$ cat ~/.julia/config/startup.jl
cat: ~/.julia/config/startup.jl: No such file or directory

I installed Julia from the official Arch Linux repo.

It seems that you’re not the only one with problems with whatever Julia is being shipped by Arch: Clean Julia 1.0 install on Arch Linux -- Can't add packages - #11 by crbinz

You could try following the steps in that post (touching ~/.julia/environments/v1.4/Project.toml and ~/.julia/environments/v1.4/Manifest.toml` ) or you could try using the generic linux binaries from Download Julia .

Using the generic linux binaries has consistently been the best approach in my experience, although I’m not on Arch so I can’t speak to that specifically.

1 Like

Actually, are you by any chance running julia as root?

No. Just as a normal user.

Can you download the tarball from julialang.org, uncompress, and try run Julia from there? It maybe a packing bug.

I use Julia in Arch Linux. I never had any problems, but I do not use the distribution package, I download the tarball from the site, extract to /opt and make a link sudo ln -s /opt/julia-1.4.2/bin/julia /usr/bin/julia.

I’ll be going through these, but first I wanted to report back that I tried the package manager for the Termux version of Julia just now.

First off, it includes the version number in the package manager prompt. I do not get this on Arch. Second, it status actually returns something.

The point is, it’s not me, it’s my system.

touch ~/.julia/environments/v1.4/Project.toml didn’t work.

I downloaded the generic Linux binaries, extracted them to /opt and ran them with /opt/julia/bin/julia but that didn’t help.

First, this error means you have not brought Pkg into namespace or define it. If it is a module, using Pkg brings it to the current module. Second, normal users usually do not have enough privilege to write under /opt folder.

Sorry, I should have been more specific. I do have permission (I’m the owner) and I was trying pkg> status. And by that I don’t mean I typed pkg> but rather that is the prompt I get when in the package manager.

No need to be sorry. I cleary understood you have used package manager REPL at the end but I’ve just refered to the programmatical way of using it that you’ve tried at first. For the other issue, have you tried ]up to get list of pakages?

Just now, I tried ]up and it gives me the same error as with every other package manager command: “ERROR: no active project”.

What does Base.load_path_expand.(LOAD_PATH) return? and LOAD_PATH also?
I have something like

julia> Base.load_path_expand.(LOAD_PATH)
3-element Array{Union{Nothing, String},1}:
 nothing
 "/home/lutfullah/Programs/homedir/.julia/environments/v1.4/Project.toml"
 "/home/lutfullah/Programs/julia-1.4.1/share/julia/stdlib/v1.4"

julia> LOAD_PATH
3-element Array{String,1}:
 "@"
 "@v#.#"
 "@stdlib"
1 Like

Huh. I take back what I said about this not being my fault.

julia> Base.load_path_expand.(LOAD_PATH)
1-element Array{String,1}:
 "/home/nstgc5/myScripts"

julia> LOAD_PATH
1-element Array{String,1}:
 "/home/nstgc5/myScripts"

I know I set that, and I’m guessing that’s part of the problem. But I don’t know what it should be or how to make it that way.

Ok. We’re going somewhere. Any luck with ] and

(@v1.4) pkg> help activate
  activate
  activate [--shared] path

  Activate the environment at the given path, or the home project environment if no path is specified. The active environment is
  the environment that is modified by executing package commands. When the option --shared is given, path will be assumed to be a
  directory name and searched for in the environments folders of the depots in the depot stack. In case no such environment exists
  in any of the depots, it will be placed in the first depot of the stack.

(@v1.4) pkg> activate
 Activating environment at `/home/lutfullah/Programs/homedir/.julia/environments/v1.4/Project.toml`

You probably have set JULIA_LOAD_PATH as an environment variable check with ENV["JULIA_LOAD_PATH"] and you’ll see the path, otherwise it errors.

1 Like

Actually, I had it in ~/.bashrc. I vaguely remember putting it there. It’s now commented out, and…

julia> LOAD_PATH
3-element Array{String,1}:
 "@"
 "@v#.#"
 "@stdlib"

julia> Base.load_path_expand.(LOAD_PATH)
3-element Array{Union{Nothing, String},1}:
 nothing
 "/home/nstgc5/.julia/environments/v1.4/Project.toml"
 "/usr/share/julia/stdlib/v1.4"

And now the package manager works. Thank you!

3 Likes