Run julia programs like python

Hi there !
I have a question: In python if I double click on python file then the file run. How can I make this to happen on julia?

Thank you in advance!

I guess you mean that in some IDE for Python you can do that. Same with IDEs for Julia. For instance:

Most IDEs have similar ways to to that.

On Linux and OS X you could use a shebang line to make the script executable. Mind the startup time, which makes this a rarely used option in Julia for small scripts.

On Windows, at least, you would likely want to register the .jl file-ending, to do something similar, i.e. running it with preinstalled Julia, to what T.Papp suggested (note his way is for CLI, and may not be sufficient for double-clicking, even on non-Windows).++

But I think you have in mind, running your code without Julia preinstalled, and without having to do that. Then look into PackageCompiler.jl package, that can make .exe files (I’ve only tried it for Linux). It takes a lot of time to compile, but in the end your program is as fast, even a bit faster since startup-time can be reduced. Currently, the executables are huge however.

If you rather DO use the shebang way (on non-Windows, unless with WSL), then adding it like this at the top of your main Julia file can help:

#!/bin/bash
#=
exec julia -O1 --color=yes --startup-file=no "${BASH_SOURCE[0]}" "$@"
=#

Note, I added the -O1 to get LESS optimization. It helps to reduce startup time. It depends if it’s faster overall. You could also e.g. add -p4 or whatever applies to your program (or -t4 on Julia 1.5) in that (shebang) header, but would have to do those performance options differently, I think, when making a compiled app.

PackageCompiler.jl works with Julia 1.3.x, and latest 1.4 but last time I checked a bug blocked using with (the not yet released) Julia 1.5.

++ I can run my Julia file, like: ./program.jl but double-clicking on it brings it up in vim editor. I suppose I can change that if I wanted to, but I find it likely you want to configure it to run bash rather than julia (with the “shebang”), unlike on Windows. Note, you may also need to do for chmod u+x program.jl

1 Like

Thank you all. Can i run my file.jl with double click, without calling the file.jl from cmd?

I don’t use Windows to test this, but I believe this is what you want (if it’s just for you and not to distribute apps):

Here’s how done programmatically (not for Julia but would be similar):

But PackageCompiler.jl also works.

Right click on file → open with → pick your local julia.exe (which is the REPL)

Should work just fine or did I misunderstand you?

Edit: If you find that your terminal closes too quickly, you might want to insert a readline() at the end of your script. This way it will only end and close the REPL when you press enter.

1 Like

Thank you! Thats is what i want!