PyCall: couldn't find libpython


I’m in the rather unfortunate position of having to use CentOS (unfortunate because everything on the latest version of CentOS is ancient). Anyway, of course there is no way of installing a reasonablly recent version of python 3 via the package manager (because nobody uses that, right?) so I’ve had to install python 3.6 using python’s make.

Anyway, the python interpreter itself seems to work ok. But when I try installing PyCall with my python3 binary, it can’t seem to find the libraries.

LoadError: Couldn't find libpython; check your PYTHON environment variable.                                                                                                                                
The python executable we tried was /usr/local/bin/python3 (= version 3.6);                                                                                                                                    
the library names we tried were String["libpython3.6m.a", "libpython3.6m", "libpython3.6", "libpython"]                                                                                                 
and the library paths we tried were String["/usr/local/lib", "/usr/local/lib", "/usr/local", "/usr/local/lib"]                                                                                            
while loading /home/msavastio/.julia/v0.6/PyCall/deps/build.jl, in expression starting on line 255        

Thing is, libpython3.6m.a actually is in /usr/local/lib. Obviously this is a static library, so PyCall shouldn’t be looking for it right? Do I have to figure out a way to get python to build that dynamic libraries, or is there something else wrong?

LoadError: Couldn't find libpython PyCall

Yes, there’s a flag for it.

(btw, have you checked DevToolSet for a suitable Python version? I believe they have some version of Python3)


Hm… I’ve compiled the shared libraries (now have and in /usr/local/lib) bit it still seems not to find them, throwing:

/usr/local/bin/python3: error while loading shared libraries: cannot open shared object file: No such file or directory


Ok, the problem was that the compiled python3 binary was using LD_LIBRARY_PATH instead of ldconfig or whatever it is that everything else uses when it links to all the usual locations. Fixed now.


I’m sure you’ve been given good advice already, just not sure if that way is needed.

It’s not completely clear from PyCall’s documentation that you can just use Conda to provide Python 3[.6] (not at all or only for non-Linux?). Python 3 is supported and Python 2 at least with Conda.

You can at least do ENV[“PYTHON”] = “” to get Python 2 from Conda (see doc). I did look a bit into the code and: