Skip to content

Python package library (ortools) conflicts with another Julia package (Clp) after import the Julia package firstly #802

@szcf-weiya

Description

@szcf-weiya

I am not sure if this issue/problem related to the PyCall.
My working environment is

julia> versioninfo()
Julia Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
(@v1.4) pkg> status
Status `~/.julia/environments/v1.4/Project.toml`
  [e2554f3b] Clp v0.7.1
  [093fc24a] LightGraphs v1.3.1
  [2f5eb75a] LightGraphsFlows v0.3.1
  [438e738f] PyCall v1.91.4
# remove unrelated (I thought) packages

and the version of Python is 3.7.5 with ortools==7.5.7466. The PyCall is well installed, since no problem when I separatedly run

module ClpFromPython
	using PyCall
	pyimport("ortools.graph.pywrapgraph")
end

It would throw an error

<class 'ImportError'>
ImportError('/home/weiya/anaconda3/envs/py37/lib/python3.7/site-packages/ortools/graph/../.libs/libClpSolver.so.1: undefined symbol: _ZN19ClpPEDualRowDantzigC1Ed')
File "/home/weiya/anaconda3/envs/py37/lib/python3.7/site-packages/ortools/graph/pywrapgraph.py", line 13, in
from . import _pywrapgraph

if I run

$ julia mwe1.jl

with the following mwe1.jl

# file mwe1.jl
module ClpFromJulia
	using LightGraphsFlows
	using Clp: ClpSolver
	import LightGraphs
	const lg = LightGraphs
	g = lg.DiGraph(2)
	lg.add_edge!(g, 1, 2)
	w = zeros(2,2)
	w[1, 2] = 1
	node_demand = zeros(2)
	node_demand[1] = 1
	node_demand[2] = -1
	capacity = ones(Int, 2, 2)
	flow = mincost_flow(g, node_demand, capacity, w, ClpSolver())
end
module ClpFromPython
	using PyCall
	pyimport("ortools.graph.pywrapgraph")
end

but all would be OK if I move the module ClpFromPython to the beginning, i.e.,

# file mwe2.jl
module ClpFromPython
	using PyCall
	pyimport("ortools.graph.pywrapgraph")
end
module ClpFromJulia
	using LightGraphsFlows
	using Clp: ClpSolver
	import LightGraphs
	const lg = LightGraphs
	g = lg.DiGraph(2)
	lg.add_edge!(g, 1, 2)
	w = zeros(2,2)
	w[1, 2] = 1
	node_demand = zeros(2)
	node_demand[1] = 1
	node_demand[2] = -1
	capacity = ones(Int, 2, 2)
	flow = mincost_flow(g, node_demand, capacity, w, ClpSolver())
end

And it would also be OK if just using the package without any program, i.e.,

# file mwe3.jl
module ClpFromPython
	using PyCall
	pyimport("ortools.graph.pywrapgraph")
end
module ClpFromJulia
	using LightGraphsFlows
	using Clp: ClpSolver
	import LightGraphs
end

Since both Julia's Clp and Python's ortools have the library libClpSolver.so, it seems that firstly running Julia code would let the following python code import the wrong library, and hence bring the error. However, I am not sure what is the detailed mechanism of loading library files in Julia, and whether PyCall affects the load library paths, since I was thinking Module would isolate different parts of code but seems not necessarily.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions