JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
715 stars 61 forks source link

IPython extension fails on Julia 1.6.7 #460

Closed MilesCranmer closed 4 months ago

MilesCranmer commented 4 months ago

Affects: JuliaCall

Describe the bug On Julia 1.6.7, I tried loading the JuliaCall IPython extension in a Jupyter notebook (as part of the PySR test suite, I have a notebook that runs and does %load_ext juliacall and does various Julia stuff).

I executed it in a line with %julia println(3). This gives me the following traceback:

JuliaError                                Traceback (most recent call last)
/tmp/ipykernel_3051/1932480696.py in <module>
----> 1 get_ipython().run_line_magic('julia', 'println(3)')

/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2416                 kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2417             with self.builtin_trap:
-> 2418                 result = fn(*args, **kwargs)
   2419             return result
   2420 
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/decorator.py in fun(*args, **kw)
    230             if not kwsyntax:
    231                 args, kw = fix(args, kw, sig)
--> 232             return caller(func, *(extras + args), **kw)
    233     fun.__name__ = func.__name__
    234     fun.__doc__ = func.__doc__
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/juliacall/ipython.py in julia(self, line, cell)
     52         ans = Main.seval('begin\n' + code + '\nend')
     53         # flush stderr/stdout
---> 54         PythonCall._flush_stdio()
     55         # copy variables back to Python
     56         # only copy those which are new or have changed value
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/juliacall/__init__.py in __call__(self, *args, **kwargs)
    206             return ValueBase.__dir__(self) + self._jl_callmethod($(pyjl_methodnum(pyjlany_dir)))
    207         def __call__(self, *args, **kwargs):
--> 208             return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
    209         def __bool__(self):
    210             return True
JuliaError: MethodError: no method matching flush(::Tuple{Base.PipeEndpoint, Base.PipeEndpoint})
Closest candidates are:
  flush(!Matched::Base.DevNull) at coreio.jl:19
  flush(!Matched::TextDisplay) at multimedia.jl:253
  flush(!Matched::IOStream) at iostream.jl:66
  ...
Stacktrace:
 [1] _flush_stdio()
   @ PythonCall ./none:11
 [2] pyjlany_call(self::typeof(PythonCall._flush_stdio), args_::Py, kwargs_::Py)
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/jlwrap/any.jl:39
 [3] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/jlwrap/base.jl:69
 [4] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
   @ PythonCall.C ~/.julia/packages/PythonCall/wXfah/src/cpython/jlwrap.jl:47

This is the most recently released version of JuliaCall. So it basically looks like this flush call is not compatible with Julia 1.6?

cjdoris commented 4 months ago

Looks like it. Can you figure out how to do that flush on 1.6?

MilesCranmer commented 4 months ago

Sorry, I don't know. Up until this point I didn't even know what flush did.

cjdoris commented 4 months ago

No worries it was a simple fix - fixed on main.

MilesCranmer commented 4 months ago

Awesome, thanks!