At some point I used the load path option but I had problems running the code from within an IDE. I was getting errors that Julia was unable to find the modules asking me to add them using Pkg.add().
Most likely you just misconfigured
JULIA_PKGDIR environment variable. Without specific symptoms it’s impossible to figure out what exactly was wrong.
I also had the same problem when trying to use the static julia compiler to create an executable since i do not care about compilation during execution and jupyter notebooks.
Julia now precompiles all modules by default. Normally you:
- Decompose your code into logical modules. Something you do in any language anyways.
- Create a package for each module and put it to your
~/.julia/v0.6 by default). You can publish your package to GitHub or keep it private.
- Create some
Main package, put
using A; using B statements to load your modules and implement application-specific logic.
- If you want to make a script from it, you can make something as simple as:
julia -e 'using Main; Main.launch()'
A note on
include(). Sometimes you want many functions to be logically in the same unit, e.g. module, class, etc., but don’t want to have files with 1000+ lines of code. The question is: how do you put code physically into separate files, but logically to a single unit?
Different languages solve this differently. In Python, for example, you usually make multiple submodules and then simply reexport functions you need. In C++ you can define the same namespace in several files. Scala guys use traits and so-called cake pattern to create a single class that “extends” its components.
Julia provides a very simple alternative: it lets you directly
include files that you want to be parts of a single module. For example, in Espresso.jl I have > 4k lines of code split into 33 files, but a single module exporting ~90 functions. Of course, if you want more logical modules, you can create more packages or a single package with several modules, each module consisting of a single file or including multiple others - whatever structure you believe is appropriate for your project. But don’t mix up
using/import - the first is for physical layout, the second is for logical units.