0

I'm trying to get the Julia version from a python script.

C:\Users> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.3 (2018-12-18)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> VERSION
v"1.0.3"

julia> exit()
C:\Users>

This is the way I do it in CMD.

Looking for a way to access this version value using python.

When using os.system('julia') it never exits this stage because I guess it is waiting for a command within this Julia environment.

  • 3
    Does [running `julia --version`](https://stackoverflow.com/q/4760215/11082165) and parsing the output fit your needs? – Brian61354270 Jun 21 '22 at 19:01
  • Yes sir, that works, I didn't consider trying it with dashes, thanks! – Alberto J Lorenzo Rosario Jun 21 '22 at 19:04
  • 2
    BTW, `subprocess.Popen(['julia'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stder=subprocess.PIPE).communicate('VERSION\nexit()\n')` is the closer equivalent to your original, but `--version` is very much the Right Thing. – Charles Duffy Jun 21 '22 at 19:06
  • 2
    `os.system()` is the wrong tool in no small part because it isn't designed to let you capture stdout at all in the first place. – Charles Duffy Jun 21 '22 at 19:07
  • Yes, I see, but that command might help me later on in capturing the version for containerized processes I have running. Yeah, I figured I was missing something when using os for this case. – Alberto J Lorenzo Rosario Jun 21 '22 at 19:08

1 Answers1

1

You can use the julia interpreter's command-line option -v in the shell:

julia -v

This system command can also be invoked from within Python using e.g. subprocess:

version_output = subprocess.check_output(['julia', '-v'])
print(version_output)

See Running shell command and capturing the output

hc_dev
  • 8,389
  • 1
  • 26
  • 38