PyCall inconsistent across machines

question
#1

I have the following code intended to access sympy’s logic functionality (not implemented in SymPy.jl)

    using PyCall
    pyimport_conda("sympy.logic", "sympy")
    py"""
    from sympy.logic import POSform
    from sympy import symbols

    def kmap_py(symstr, minterms):
        syms = symbols(symstr)
        return POSform(syms, minterms)

which I use like

julia> py"kmap_py"("b1 b2", PyVector([0,1,3]))

This works fine on one PC (running Windows 10) and gives the error below on another (Win 7). Both PCs have the same directory structure, and both are using the built in conda version (ENV["PYTHON"] == ""). Any idea what the difference could be? Here is the error

ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\julia-depot\packages\PyCall\ttONZ\src\pyfncall.jl:44 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <c
lass 'TypeError'>
TypeError("'int' object is not iterable",)
  File "C:\julia-depot\packages\PyCall\ttONZ\src\pyeval.jl", line 6, in kmap_py
  File "C:\julia-depot\conda\3\lib\site-packages\sympy\logic\boolalg.py", line 1898, in POSform
    minterms = [list(i) for i in minterms]
  File "C:\julia-depot\conda\3\lib\site-packages\sympy\logic\boolalg.py", line 1898, in <listcomp>
    minterms = [list(i) for i in minterms]
#2

Did you check that two machines have the same version of the libraries? For example, pyimport("sympy").__version__ and PyCall version printed by Pkg.status() may be useful.

1 Like
#3

Thanks! I was running sympy 1.4 (working) vs 1.3 (not working, different input syntax).

I upgraded using Conda.update(). Is there a way to specify a minimum conda package version and maybe upgrade just that automatically through pyimport_conda or similar? Thank you.

#4

pyimport_conda installs Python packages if there is an error during imports. So, it’s not very useful for constraining versions. I think you need to check package versions yourself (by looking at __version__ or using pkg_resources) and then invoke Conda.add("sympy>=1.4") (say) if you need to upgrade sympy.

If you are writing Julia packages, I think it’s better to install packages at build time. I’m proposing to add such API and deprecate pyimport_conda (although it’s stalled ATM): https://github.com/JuliaPy/PyCall.jl/pull/613

1 Like
#5

OK thanks for your help, and efforts overall.

#6

You might also just do: sympy.POSform(symbols("b1 b2"), [0,1,3]) if you want to use SymPy.jl