Adding a local package using the Pkg manager - how to add the path?

I have created a package using PkgTemplates, and everything is great. Now I want to use this package on another machine. I have copied the files. How do I add the path of the directory such that Pkg knows about it when I do add MyPackage?

You just need to supply the path to the package when you call add.

add /home/Packages/MyPackage

for example.

3 Likes

That needs to be a git repository according to the docs.

Better to ] dev path/to/package

Even better, OP, would be to put the package on github. Then you can add the git url and keep updated across machines.

2 Likes

If he used PkgTemplates it should be a git repo I believe. But yes, might as well put it on Github, even if you just make it a private repo.

It does not work for me. It seems like the package is added, but after doing using MyPackage it cannot recognize any of the function…

So using MyPackage works without error but not executing any of the functions?

Exactly.

Please post the error messages. Are you sure your MyPackage is exporting the functions? Can you call MyPackage.foo?

Yes. On my 1st machine everything works great.
On the other machine it doesn’t. the error message is just

julia> MyPackage.foo
ERROR: UndefVarError: foo not defined

what does your src/MyPackage.jl code look like?

module pendulum

greet() = print("Hello World!")

import Elliptic

include("pendulum_physical_functions.jl")
export I_elliptic, ω_elliptic, θ1_elliptic, θ0_elliptic, q_of_θ1_elliptic, q_of_θ0_elliptic, p_of_q, S_generating_function, E_of_λ, E_of_t, θdot_of_θ0_for_sin_squeezing, θdot_of_θ1_for_sin_squeezing

end # module

BTW, I would upload this to git to solve the problem, but I am not sure how to do that. I tried to create a new repository on GitHub, and then to push. But I think that the PkgTemplates already set the remote, and therefore I can’t do it now.
Do you know how to make it work?

I’m not sure if PkgTemplate would have set the remote or not. You can do

git remote -v

from the command line or a Git shell to see what your remotes are set as.

My typical workflow

  • create package locally, get it partially working
  • create repo on Github website. just leave it empty when you create it.
  • set origin on my local repo to be the newly created remote repo. I use the ssh version because I have previously setup ssh keys. git remote add origin git@github.com:username/reponame.git
  • git push -u origin master to push everything to remote (assumes you have master checked out)

This is what I did. But I get get permission denied error:

Rois-MBP:pendulum roi$ git remote -v
origin	git@github.com:roiholtzman/pendulum.jl.git (fetch)
origin	git@github.com:roiholtzman/pendulum.jl.git (push)


Rois-MBP:pendulum roi$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '140.82.118.3' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Then you have set the repo as private and you have not properly set up ssh access from that computer. Once you set up ssh keys with Github it should work fine.

https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

Thanks. I will try.

But anyway, there is not way to simply let Pkg know about a local package?

I do not understand what the PkgTemplates did so that I can simply do add MyPackage in the first machine. Can’t I do it in the second machine?

My intuition is that it’s overkill to get set up on git just to fix this problem. I think there must be some step you missed in getting set up. Can you try and give an MWE (or, list your steps) for how you got set up?

I have generated my package using a template with PkgTemplates, and everything is working great.

On my 1st machine I have been using this packages successfully from day one.

Now, I want to use the package on my other machine (I have dropbox connecting them, so the same folder is simply on my other machine as well).

When I do add MyPackage on the other machine, it looks fine. things are happening:

(v1.3) pkg> add /PATH/to/pendulum
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Updating git-repo `/PATH/to/pendulum`
  Updating git-repo `/PATH/to/pendulum`
 Resolving package versions...
 Installed Contour ─ v0.5.3
  Updating `~/.julia/environments/v1.3/Project.toml`
 [no changes]
  Updating `~/.julia/environments/v1.3/Manifest.toml`
  [d38c429a] ↑ Contour v0.5.2 ⇒ v0.5.3

julia> using pendulum

julia> pendulum.E_of_t
ERROR: UndefVarError: E_of_t not defined

julia> E_of_t
ERROR: UndefVarError: E_of_t not defined


but as you can see, I can’t access the functions in the package.

Does it work if you do dev instead of add?

2 Likes

I tried dev and it might help.
I did not see any change. But then I exited julia, and started it again. Now using MyPackage works just fine!!!
THANKS!