In this post, I will show you how to create your own Julia package in just a few easy steps. I have found the Julia programming language about a year ago and since then I am a huge fan. My thesis required a lot of time-consuming Monte Carlo simulations and originally the code was written in MatLab and it was just fine to finish my thesis but I still have plans to publish the study at some point. To achieve that goal I needed a more scalable solution, not just a simple script.
My first idea was to re-implement everything in Python, however, I quickly realized that Python was not much faster and the way how NumPy handles matrices and vectors is just not for me. I always try to keep an open eye on exciting programming languages and when I heard that there is one out there that combines features from MatLab and Python and it is said to be super fast, I had to look into it. In my opinion, Julia has its issues and for most of my work I am still using Python as default, however, to implement my MCMC simulation-based models, Julia is just a really good choice. As my codebase grew, I started thinking about how could I convert it to a proper package type of project, and as it turned out, it is quite easy, you just have to follow these steps:
cd("..")
and pwd()
help)]
, this activates the Julia Package Managergenerate YourPackageName
to generate your packagecd("YourPackageName")
]
and run activate .
, this will activate your package. Now the package is ready to use, but if you want to import other packages within your project, you have to add those by ]
and add OtherPackages
(eg Distributions, LinearAlgebra, etc.)import
the package and run your implemented functionsTips and tricks, and some additional info:
src
folder that will have all your implemented codesProject.toml
and Manifest.toml
files are responsible for handling the added external packagestest/runtests.jl
. Running the tests is very easy, type ]
and run test YourPackageName
]
and add Revise
). It is a very useful package during the development of your project. Before importing your package, load Revise using Revise
. If you make changes to your code it will automatically use the updated version and you don’t have to reload Juliainclude("path_to_package\\YourPackageName\\src\\YourPackageName.jl")
and use it with using .YourPackageName