How to create a Julia object
I have Julia v.0.6.4 downloaded and I accomplish to link it using PyCall v.0.4.1 by running
import julia
julia.install(julia="/home/developer/JuliaPro-0.6.4.1/Julia/bin/julia")
Once I have that I do not see in the documentation how to call a function from a certain directory, in Julia I would do:
include("setup.jl")
function(..)
I have tried this:
j = julia.Julia(runtime="/home/developer/JuliaPro-0.6.4.1/Julia/bin/julia")
signal (11): Segmentation fault
while loading no file, in expression starting on line 0
But gives SegmentationFault
In principle, this should work:
import julia
j = julia.Julia(runtime="/home/developer/JuliaPro-0.6.4.1/Julia/bin/julia")
from julia import Main
Main.include("PATH/TO/setup.jl")
I'm not sure what is going on with the segmentation fault. Can you put the rest of the stacktrace? You can also enable debug-level messages with julia.Julia(..., debug=True).
j = julia.Julia(runtime="/home/developer/JuliaPro-0.6.4.1/Julia/bin/julia",debug=True)
DEBUG
DEBUG Debug-level logging is enabled for PyJulia.
DEBUG PyJulia version: 0.4.1
DEBUG
DEBUG pyprogramname = /home/developer/anaconda3/envs/motionplanningthesishector/bin/python
DEBUG sys.executable = /home/developer/anaconda3/envs/motionplanningthesishector/bin/python
DEBUG bindir = /home/developer/JuliaPro-0.6.4.1/Julia/bin
DEBUG libjulia_path = /home/developer/JuliaPro-0.6.4.1/Julia/bin/../lib/libjulia.so.0.6
DEBUG py_libpython = None
DEBUG jl_libpython = /home/developer/anaconda3/envs/motionplanningthesishector/lib/libpython3.7m.so.1.0
DEBUG use_separate_cache = True
DEBUG calling jl_init_with_image(/home/developer/anaconda3/envs/motionplanningthesishector/lib/python3.7/site-packages/julia/fake-julia, /home/developer/JuliaPro-0.6.4.1/Julia/lib/julia/sys.so)
DEBUG seems to work...
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG
signal (11): Segmentation fault
while loading no file, in expression starting on line 0
And this is the result if I run install again:
julia.install(julia="/home/developer/JuliaPro-0.6.4.1/Julia/bin/julia")
INFO: Julia version info
Julia Version 0.6.4
Commit 9d11f62bcb (2018-07-09 19:09 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
WORD_SIZE: 64
Ubuntu 18.04.3 LTS
uname: Linux 5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64
Memory: 31.28787612915039 GB (17899.41015625 MB free)
Uptime: 78320.0 sec
Load Avg: 5.70556640625 5.40966796875 5.14306640625
Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz:
speed user nice sys idle irq
#1 3140 MHz 582216 s 1939 s 1540178 s 5665965 s 0 s
#2 3140 MHz 585918 s 1821 s 1465890 s 5652433 s 0 s
#3 3140 MHz 607137 s 1275 s 1447526 s 5749041 s 0 s
#4 3140 MHz 630512 s 1256 s 1511477 s 5659556 s 0 s
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
Environment:
PATH = /home/developer/anaconda3/envs/motionplanningthesishector/bin:/home/developer/anaconda3/condabin:/home/developer/.local/bin:/home/developer/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
MANDATORY_PATH = /usr/share/gconf/ubuntu.mandatory.path
DEFAULTS_PATH = /usr/share/gconf/ubuntu.default.path
PYTHONPATH = /snap/pycharm-community/175/plugins/python-ce/helpers/third_party/thriftpy:/snap/pycharm-community/175/plugins/python-ce/helpers/pydev
SNAP_LIBRARY_PATH = /var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void
WINDOWPATH = 2
HOME = /home/developer
Package Directory: /home/developer/.julia/v0.6
1 required packages:
- PyCall 1.18.5
6 additional packages:
- Compat 2.2.0
- Conda 1.0.2
- JSON 0.17.2
- MacroTools 0.4.5
- Nullables 0.0.8
- VersionParsing 1.1.3
INFO: Julia executable: /home/developer/JuliaPro-0.6.4.1/Julia/bin/julia
INFO: Trying to import PyCall...
INFO: PyCall is already installed and compatible with Python executable.
PyCall:
python: /home/developer/anaconda3/envs/motionplanningthesishector/bin/python
libpython: /home/developer/anaconda3/envs/motionplanningthesishector/lib/libpython3.7m.so.1.0
Python:
python: /home/developer/anaconda3/envs/motionplanningthesishector/bin/python
libpython:
Nevertheless, if I run the same commands over the Python from the Terminal (before I was using PyCharm) it works, but the Python executable used is the same in both places, do you know what may happen?
Moreover, in my "setup.jl" I include:
using JuMP, Ipopt, PyPlot, NearestNeighbors, ControlSystems, NPZ
Even though I already installed them in my current julia (they appear in /home/developer/.julia/packages) it tells me:
>>> Main.include("optimizers/H-OBCA/setup.jl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Julia exception: LoadError("/home/developer/thesismotionplanning/Planner/optimizers/H-OBCA/setup.jl", 35, ArgumentError("Module JuMP not found in current path.\nRun `Pkg.add(\"JuMP\")` to install the JuMP package."))
if I run the same commands over the Python from the Terminal (before I was using PyCharm) it works, but the Python executable used is the same in both places, do you know what may happen?
It's hard to tell without stacktrace and/or debug log. Maybe different environment variable?
they appear in
/home/developer/.julia/packages
This does not necessary mean that the packages are importable. Only the packages that are included in Project.toml of the current environment are importable (roughly speaking). (assuming that you are using Julia >= 1 now)
You can check it by
>>> from julia import Pkg
>>> Pkg.status()
in Python REPL or
julia> using Pkg
julia> Pkg.status()
in Julia REPL.
Anyway, the correct solution here is to follow what the error message said
Run `Pkg.add(\"JuMP\")` to install the JuMP package."
So run Pkg.add("JuMP") and other dependencies.
After installing once again julia , new location is:
/home/developer/julia-1.0.5/bin/julia
From Python (which is a conda environment) I do:
>>> import julia
>>> j = julia.Julia(runtime="/home/developer/julia-1.0.5/bin/julia", compiled_modules=False)
>>> from julia import Main
>>> Main.include("setup.jl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Julia exception: LoadError: LoadError: LoadError: UndefVarError: @variable not defined
Stacktrace:
[1] top-level scope
[2] include at ./boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1044
[4] include(::Module, ::String) at ./sysimg.jl:29
[5] include(::String) at ./client.jl:392
[6] top-level scope at none:0
[7] include at ./boot.jl:317 [inlined]
[8] include_relative(::Module, ::String) at ./loading.jl:1044
[9] include(::Module, ::String) at ./sysimg.jl:29
[10] include(::String) at ./client.jl:392
[11] #invokelatest#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:697
[12] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:696
[13] _pyjlwrap_call(::Function, ::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}) at /home/developer/.julia/packages/PyCall/ttONZ/src/callback.jl:28
[14] pyjlwrap_call(::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}) at /home/developer/.julia/packages/PyCall/ttONZ/src/callback.jl:49
in expression starting at /home/developer/thesismotionplanning/Planner/optimizers/H-OBCA/trajectory_without_obstacles.jl:18
in expression starting at /home/developer/thesismotionplanning/Planner/optimizers/H-OBCA/trajectory_without_obstacles.jl:1
in expression starting at /home/developer/thesismotionplanning/Planner/optimizers/H-OBCA/setup.jl:43
The error is related to a JuMP variable but again from my julia I can run this code without a problem