Julia has a detailed, comprehensive, punctilious package management system. As a user of Julia, I am grateful for this.
I’m finishing up a paper. Part of it is a new solver for some nonlinear PDEs. Although I’m a seasoned programmer, I’m a novice when it comes to Julia so I apologize in advance.
I’ve spent a couple of days reading tutorials on how to make packages with Julia, and I’ve tried and failed to do this with my software. This is perhaps not entirely bad, reading this, it seems like simply having a package in the registry requires an engineer to monitor things because upper version numbers need to be kept up to date. It also doesn’t help that I seem to be the only one using jupyter, everyone else is using vscode. I don’t think ] works to do Pkg commands.
So I have given up on having my package in the registry, but I am wondering if there’s a way I can make my package “easy to use” even if it’s not in the registry? Is it easier to make a package that is to be installed via Pkg.add(url=“https://github.com/…”)?
Also, it is tremendously confusing to me to then have to Pkg add my own package, then Pkg dev it, and now it’s in ~/.julia, so it’s not in my Dropbox anymore. Also, Julia seems to want to know my Github username and passwords, can that be simplified down? What is the minimal way that I can put my package on Github, have it simple for me to develop, but also have other people be able to use it?
Edit. Solution was found by several people, I’ve credited nsajko. My main problem was that LOAD_PATH and JULIA_LOAD_PATH can interact in a confusing manner with package loading, and apparently their use is discouraged. I had . in my JULIA_LOAD_PATH. Once I deleted it from the path, I was able to do using MyPackage. Details in the thread below.
Thank you so much for the links. I’ve already read those links and attempted the techniques therein, but unfortunately, I have failed. After activating my package and adding dependencies, I got baffling error messages when I did “using MyPackage”. I’ve reverted all of this because I needed to be able to work on my package, and it was no longer functional under this package infrastructure. Because I’ve reverted all these changes, I can’t tell you the literal error messages.
Roughly speaking, it told me that the dependencies had not been properly installed, and it suggested a Pkg command to fix it. The Pkg command it suggested did nothing.
Part of the issue may be that I found no clear explanation of “projects”. I think all the tutorials that explain how to make packages, gloss over which project should be activated at what time.
[ Info: Precompiling SpectralBarrierMethod [aee288fa-9512-4637-b72d-5ce5ca970827]
ERROR: LoadError: ArgumentError: Package ForwardDiff [f6369f11-7733-5829-9624-2563aa707210] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
(same error message)
Personally, I don’t use projects at all, they’re certainly not necessary, but I assume using projects can be convenient in some cases.
Start from installing ForwardDiff into your root environment (which is named after my Julia version, for me, at least). You can do it from the Pkg REPL, which can be entered from the basic REPL by entering ]. After that just enter add ForwardDiff.
I’ve never used environment before. I can’t say I like them, but that’s not my decision to make. If you are aware of a way of making a package that people can install, all that without having to mess with environments, then I’d love to hear it.
Actually, I advise against storing packages that you may modify locally in ~/.julia, when you value the local changes. You can always do dev path/to/package/directory to choose the directory explicitly. PkgTemplates also defaults to storing to ~/.julia for some reason.
Briefly, do ]generate Foo to create a blank package, then add using ForwardDiff to Foo.jl, then ]activate Foo and ]add ForwardDiff. Finally, try using Foo, you’ll get the above error message. No combination of ]instantiate and ]resolve are of any help to me.
EDIT2: to clarify, the load path is mostly used for testing/debugging things, at least nowadays. I don’t have it set up (it has the default value), so I’m guessing you have a leftover setting for load path that makes it prefer packages in the current directory to the global packages, or something like that. This is how it looks for me:
There are a number of different ways. When you’re developing Bar, I typically want to be in that working directory. But you could also make a separate project with Bar as a dependency. Eg, you’re in ./my_project, and it has a subfolder ./my_project/Bar, you can do ] activate ., then add ./Bar, which will make ./my_project/Project.toml with Bar as a dependency.