Installating Julia/IJulia (version of 2019-08-25)

Warning: as of 2019-08-25, the Julia installation is not supposed to support a move of Winpython library

read also https://pyjulia.readthedocs.io/en/latest/installation.html#step-1-install-julia

other intesting note: or https://discourse.julialang.org/t/using-jupyterlab/20595/2 or https://blog.jupyter.org/i-python-you-r-we-julia-baf064ca1fb6

0 - mandatory and only pre-requisites (prepared, in WinPython 2019-03+)

"pip install pyjulia" pyjulia python package "set PYTHON=%WINDPYDIR%\python.exe" in your %WINPYDIR%..\scripts\ENV.BAT

1 - Downloading and Installing the right Julia binary in the right place


In [ ]:
import os
import sys
import io

In [ ]:
# downloading julia (32Mo, may take 1 minute or 2)
try:
    import urllib.request as urllib2  # Python 3
except:
    import urllib2  # Python 2
if 'amd64' in sys.version.lower():
    julia_binary="julia-1.2.0-win64.exe"
    julia_url="https://julialang-s3.julialang.org/bin/winnt/x64/1.2/julia-1.2.0-win64.exe"
    hashes=("5ccb7d585f854f3a3d1c6d3db07b6c0f", "93A94ED6429463E585B7B7E2CAC079F92820F71D" )
else:
    julia_binary="julia-1.2.0-win32.exe"
    julia_url="https://julialang-s3.julialang.org/bin/winnt/x86/1.2/julia-1.2.0-win32.exe"
    hashes=("a2a0ab81bd639339970248c808316f23", "b5e0e5b6f0e5a737f4de9baa758b3ab50e2d52cb")
    
julia_installer=os.environ["WINPYDIR"]+"\\..\\t\\"+julia_binary
os.environ["julia_installer"]=julia_installer
g = urllib2.urlopen(julia_url) 
with io.open(julia_installer, 'wb') as f:
    f.write(g.read())
g.close
g = None

In [ ]:
#checking it's there
!dir %julia_installer%

In [ ]:
# checking it's the official julia0.3.2
import hashlib
def give_hash(of_file, with_this):
    with io.open(julia_installer, 'rb') as f:
        return with_this(f.read()).hexdigest()  
print (" "*12+"MD5"+" "*(32-12-3)+" "+" "*15+"SHA-1"+" "*(40-15-5)+"\n"+"-"*32+" "+"-"*40)

print ("%s %s %s" % (give_hash(julia_installer, hashlib.md5) , give_hash(julia_installer, hashlib.sha1),julia_installer))
assert give_hash(julia_installer, hashlib.md5) == hashes[0].lower() 
assert give_hash(julia_installer, hashlib.sha1) ==  hashes[1].lower()

In [ ]:
# will be in env next time
import os
os.environ["JULIA_HOME"] = os.environ["WINPYDIR"]+"\\..\\t\\Julia\\bin\\"
os.environ["JULIA_EXE"]="julia.exe"
os.environ["JULIA"]=os.environ["JULIA_HOME"]+os.environ["JULIA_EXE"]
os.environ["JULIA_PKGDIR"]=os.environ["WINPYDIRBASE"]+"\\settings\\.julia"
# for installation we need this
os.environ["JULIAROOT"]=os.path.join(os.path.split(os.environ["WINPYDIR"])[0]  , 't','julia' )

In [ ]:
# let's install it (add a  /S before /D if you want silence mode installation)
#nullsoft installers don't accept . or .. conventions

# If you are "USB life style", or multi-winpython
#   ==> UN-CLICK the OPTION 'CREATE a StartMenuFolder and Shortcut' <== (when it will show up)
!start cmd /C %julia_installer% /D=%JULIAROOT%


In [ ]:
# connecting Julia to WinPython (only once, or everytime you move things)
import julia
julia.install()

In [ ]:
%load_ext julia.magic

In [ ]:
%%julia  
import Pkg;
Pkg.add("PyPlot")
Pkg.add("Interact")
Pkg.add("Compose")
Pkg.add("SymPy")
Pkg.add("JuMP")
Pkg.add("Ipopt")

3 - Launching a Julia Notebook

choose a Julia Kernel from Notebook, or Julia from Jupyterlab Launcher

4 - Julia Magic

or use %load_ext julia.magic then %julia or %%julia


In [ ]:
import julia
%matplotlib inline
%load_ext julia.magic

In [ ]:
# since Julia 1.x ''@pyimport foo' is replaced per 'foo = pyimport("foo")'' 
%julia plt = pyimport("matplotlib.pyplot")
%julia np = pyimport("numpy")

In [ ]:
%%julia                                        
t = np.linspace(0, 2*pi,1000);             
s = np.sin(3*t + 4*np.cos(2*t));           
fig = plt.gcf()                         
plt.plot(t, s, color="red", linewidth=2.0, linestyle="--", label="sin(3t+4.cos(2t))")

In [ ]:
#Alternative
import julia
j=julia.Julia()
j.eval("1 +31")
j.eval("sqrt(1 +31)")

In [ ]: