Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import PyPlot #140

Closed
rgiordan opened this issue Jul 2, 2015 · 38 comments
Closed

Cannot import PyPlot #140

rgiordan opened this issue Jul 2, 2015 · 38 comments

Comments

@rgiordan
Copy link

rgiordan commented Jul 2, 2015

As of a few days ago, I lost the ability to import PyPlot. My error message is different from others that I saw in issues, and I didn't find a good resolution.

The error is below. I'm running Ubuntu 15.04 and have only a single python install on my system. My python libraries were installed with pip and work fine in python. Also, in julia I can successfully @pyimport scimath.

Any ideas?

julia> using PyPlot
Warning: error initializing module PyPlot:
PyCall.PyError(msg=":PyImport_ImportModule", T=PyCall.PyObject(o=0x0000000017ea3b80), val=PyCall.PyObject(o=0x0000000016068050), traceback=PyCall.PyObject(o=0x0000000015a3acb0))

julia> using PyCall
julia> @pyimport matplotlib.pyplot as plt
Warning: imported binding for plt overwritten in module Main
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('cannot import name scimath',)
  File "/home/rgiordan/.local/lib/python2.7/site-packages/matplotlib/__init__.py", line 180, in <module>
    from matplotlib.cbook import is_string_like
  File "/home/rgiordan/.local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 17, in <module>
    from . import scimath as emath

 in pyerr_check at /home/rgiordan/.julia/v0.3/PyCall/src/exception.jl:58
 in pyimport at /home/rgiordan/.julia/v0.3/PyCall/src/PyCall.jl:91
@stevengj
Copy link
Member

stevengj commented Jul 3, 2015

See also JuliaPy/PyCall.jl#65

@rgiordan
Copy link
Author

rgiordan commented Jul 3, 2015

As suggested by the other thread, I also tried setting LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgfortran.so.3, but it didn't fix the problem.

@kzapfe
Copy link

kzapfe commented Jul 9, 2015

Same issue here, both with Julia 0.3.7 and 0.4. I also looked into the other thread, but as I tried to replicate @cberzan errors, I did not get any. And I can do

julia> using PyCall
julia> @pyimport matplotlib.pyplot as plt

without obtaining errors.

It gets weirder... ¿does PyPlot try to use python2.7 as its matplotlib interpreter?

@stevengj
Copy link
Member

stevengj commented Jul 9, 2015

PyPlot (via PyCall), uses whatever python is in your PATH as its default Python (or, technically, the corresponding libpython library). You can change this by setting the PYTHON environment variable before loading PyPlot/PyCall, as documented in the PyCall README.

Try

run(`python --version`)

if you aren't sure which Python Julia is finding. If you have multiple Pythons installed, it may not be the one you think.

@rgiordan
Copy link
Author

Can you suggest a temporary workaround? I have a lot of analysis code built around PyPlot, and I can't use any of it right now.

I'm running the python binary I expect to (python 2.7) and I downgraded to numpy 1.6.1 and matplotlib 1.1.1 per the other thread. I'm still having the same problem importing PyPlot. Also, I now have the below problem importing numpy.

julia> using PyCall

julia> @pyimport numpy
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.AttributeError'>
AttributeError("'module' object has no attribute 'core'",)
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
    import add_newdocs
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 13, in <module>
    from polynomial import *
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 11, in <module>
    import numpy.core.numeric as NX

 in pyerr_check at /home/rgiordan/.julia/v0.3/PyCall/src/exception.jl:58
 in pyimport at /home/rgiordan/.julia/v0.3/PyCall/src/PyCall.jl:91

@stevengj
Copy link
Member

It's hard to debug remotely, unfortunately. My best guess is that it's some kind of Python-path snafu, where the pip-installed Python packages are getting confused with the Ubuntu-installed Python packages unless you have the environment set up correctly. Running python sets up the environment correctly, but linking directly to libpython as we do requires us to set up the environment manually.

Are you sure you don't have more than one Python 2.7 installed, and PyCall is using the wrong one? Try setting PYTHON to the explicit path of the Python that you want.

@rgiordan
Copy link
Author

I know it's tricky to help remotely, and I appreciate the help.

Setting PYTHON doesn't seem to make any difference, see below. (I got similar results pointing PYTHON to a virtual environment with only matplotlib and numpy installed.) What is the next place you might look?

rgiordan@kokshetau:~/Documents/git_repos/Celeste.jl$ export PYTHON=/usr/bin/python
rgiordan@kokshetau:~/Documents/git_repos/Celeste.jl$ julia
splash screen...
julia> using PyPlot
Warning: error initializing module PyPlot:
PyCall.PyError(msg=":PyImport_ImportModule", T=PyCall.PyObject(o=0x00000000f17f2440), val=PyCall.PyObject(o=0x00000000ef1a8560), traceback=PyCall.PyObject(o=0x00000000ef1a8518))
julia> ENV["PYTHON"]
"/usr/bin/python"

@stevengj
Copy link
Member

Where is pip installing things? Maybe try to set your PYTHONPATH accordingly?

@rgiordan
Copy link
Author

Aha, I do indeed have two sets of libraries, as you said. One is in ~/.local/lib/python, and the other is in /usr/local/lib/python2.7. pip and the python binary are using the former.

Setting PYTHONPATH doesn't seem to change juila's behavior, though. Is there a way to tell in julia which package file is being loaded?

rgiordan@kokshetau:/usr/local/lib/python2.7$ export PYTHONPATH=/home/rgiordan/.local/lib/python2.7/
rgiordan@kokshetau:/usr/local/lib/python2.7$ julia 
julia> ENV["PYTHONPATH"]
"/home/rgiordan/.local/lib/python2.7/"
julia> using PyPlot
Warning: error initializing module PyPlot:
PyCall.PyError(msg=":PyImport_ImportModule", T=PyCall.PyObject(o=0x00000000b93a8440), val=PyCall.PyObject(o=0x00000000b6e755a8), traceback=PyCall.PyObject(o=0x00000000b6e75560))

@rgiordan
Copy link
Author

Any ideas? I have removed the libraries from /usr/local/lib and set PYTHONPATH, to /usr/bin/python2.7 and I still get the same error.

@stevengj
Copy link
Member

PYTHONPATH is the path of the Python packages, not libpython

@rgiordan
Copy link
Author

rgiordan commented Aug 2, 2015

For the time being I've given up on using PyPlot in julia and have developed workarounds using other languages. That's too bad, though, because I like julia a lot otherwise. So if anyone out there can think of ideas for even digging into what is wrong, it would be helpful.

I'll re-summarize. I only one place where scimath and numpy are installed, and they're where pip puts them, in /home/rgiordan/.local/lib/python2.7/site-packages/.

I can @pyimport scimath but not @pyimport numpy, the latter ostensibly because it can't import scimath:

julia> using PyCall
julia> @pyimport scimath
julia> @pyimport numpy
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('cannot import name scimath',)
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/rgiordan/.local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 17, in <module>
    from . import scimath as emath

 in pyerr_check at /home/rgiordan/.julia/v0.3/PyCall/src/exception.jl:58
 in pyimport at /home/rgiordan/.julia/v0.3/PyCall/src/PyCall.jl:91

Setting PYTHONPATH=/home/rgiordan/.local/lib/python2.7/site-packages/ does not change this behavior.

@kersulis
Copy link

I am having this same issue, and the LD_PRELOAD trick isn't working for me.

I can install numpy 1.7.0 and matplotlib 1.4.1 and import them using PyCall, but then I run into a different problem: when I use plot in a Jupyter notebook I get something like

1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0x7eff93cff048>

and no plot appears (I can use savefig though). It hurts not being able to use PyPlot.jl in Jupyter. Has anyone discovered anything new regarding this issue?

@stevengj
Copy link
Member

@kersulis, to get inline plots, you need to use the PyPlot module, not @pyimport matplotlib.pyplot directly. I'm confused: @pyimport matplotlib.pyplot works for you, but using PyPlot doesn't?

@kersulis
Copy link

My apologies for the confusion, I should have referenced this PyCall issue. I commented here because it seems like this is where the discussion about @pyimport numpy issues is taking place.

What I meant about inline plotting is that I am running using PyPlot followed by plot, but then I'm only seeing a PyObject returned -- the plot is generated but hidden. (Again, this is happening with numpy 1.7 and matplotlib 1.4.1 installed. I downgraded to these versions in order to be able to import them with PyCall.jl.)

@nowozin
Copy link

nowozin commented Sep 14, 2015

I also have the exact same issue as the original reporter, running on Ubuntu 15.04, with both Julia 0.4.0-rc1 binaries and with 0.3.10 from the Ubuntu repo.

There is only one Python installation (the default Ubuntu 15.04) and running ";python --version" from Julia gives "Python 2.7.9".

Symptoms

  • using PyPlot fails with
ERROR: LoadError: InitError: Failed to pyimport("matplotlib"): PyPlot will not work until you have a functioning matplotlib module.  PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('cannot import name scimath',)
  • using PyCall, then @pyimport matplotlib fails with the same error.
  • Starting a normal Python python from the default system shell and from within Julia (via ;python) allows an import matplotlib without any issues.

Things I have tried

  • pip install --user matplotlib, as well as scimath, then using PYTHONPATH=$HOME/.local/lib/python2.7/site-packages before starting Julia.
  • Setting PYTHONPATH to various system paths appearing in sys.os.path from within Python.

This has been the case since around one week for me and has been a total blocking issue for any PyPlot plotting. As a workaround I have done some limited plotting with Winston. I really hope we can track down this issue.

@stevengj
Copy link
Member

Have you tried Pkg.checkout("PyCall"); Pkg.build("PyCall") to get the latest version?

@nowozin
Copy link

nowozin commented Sep 15, 2015

Hi Steven,

thanks for the help, here is the output.
The failure message is different, not finding cgemv_ in liblapack!

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-rc1 (2015-09-09 16:07 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-unknown-linux-gnu

julia> Pkg.checkout("PyCall")
INFO: Checking out PyCall master...
INFO: Pulling PyCall latest master...
INFO: No packages to install, update or remove

julia> Pkg.build("PyCall")
INFO: Building PyCall
INFO: PyCall is using python (Python 2.7.9) at /usr/bin/python, libpython = libpython2.7

julia> using PyCall
INFO: Precompiling module PyCall...

julia> @pyimport matplotlib
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('/usr/lib/liblapack.so.3: undefined symbol: cgemv_',)
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 180, in <module>
    from matplotlib.cbook import is_string_like
  File "/usr/lib/python2.7/dist-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 50, in <module>
    from .linalg import *
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg

 [inlined code] from /home/sn/.julia/v0.4/PyCall/src/exception.jl:82
 in pyimport at /home/sn/.julia/v0.4/PyCall/src/PyCall.jl:321

julia> 

On further digging, /usr/lib/liblapack.so.3 is a symlink pointing to /etc/alternatives/liblapack.so.3, which is again a symlink pointing to usr/lib/openblas-base/liblapack.so.3, which is a file from the libopenblas-base package, for which apt-cache show libopenblas-base gives me two install candidates:

Package: libopenblas-base
Priority: optional
Section: universe/libs
Installed-Size: 35357
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian Science Team <[email protected]>
Architecture: amd64
Source: openblas
Version: 0.2.12-1ubuntu1
Replaces: libatlas3gf-base (<< 3.8.4-4), libblas3gf (<< 1.2.20110419-3)
Provides: libblas.so.3, liblapack.so.3
Depends: libc6 (>= 2.14), libgfortran3 (>= 4.3), libblas-common
Breaks: libatlas3gf-base (<< 3.8.4-4), libblas3gf (<< 1.2.20110419-3)
Filename: pool/universe/o/openblas/libopenblas-base_0.2.12-1ubuntu1_amd64.deb
Size: 4821646
MD5sum: 8ffd5d5f2c50a39f547da8b82f6a442a
SHA1: 035a393cc18a70a966f3fb6a54a039784f4e017f
SHA256: 4d4602a2fc6bd61891faae3c76256c5a194df6b2ea3e105238f8b484fea5739a
Description-en_GB: Optimized BLAS (linear algebra) library based on GotoBLAS2
 OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
 .
 Unlike Atlas, OpenBLAS provides a multiple architecture library.
 .
 All kernel will be included in the library and dynamically switched to the
 best architecture at run time (only on x86 arches).
 .
 For more information on how to rebuild locally OpenBLAS, see the section:
 "Building Optimized OpenBLAS Packages on your ARCH" in README.Debian
Description-md5: 6a2966277c104a4f572ddd6835755301
Built-Using: lapack (= 3.5.0-4)
Homepage: https://github.com/xianyi/OpenBLAS
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

Package: libopenblas-base
Source: openblas
Priority: optional
Section: libs
Installed-Size: 22237
Maintainer: Debian Science Team <[email protected]>
Architecture: amd64
Version: 0.2.10.1-vivid1
Replaces: libatlas3gf-base (<< 3.8.4-4), libblas3gf (<< 1.2.20110419-3)
Suggests: liblapack3
Provides: libblas.so.3, libblas.so.3gf
Depends: libc6 (>= 2.4)
Breaks: libatlas3gf-base (<< 3.8.4-4), libblas3gf (<< 1.2.20110419-3)
Filename: pool/main/o/openblas/libopenblas-base_0.2.10.1-vivid1_amd64.deb
Size: 1022124
MD5sum: a5a59ad62678e141bfd02e3e4637da3d
SHA1: 033c0a356dcef85502ff86159f9d9d82e72cee63
SHA256: ad3564c8aa37b49f9a10285ba221b1e892a97487e54bab2134d4662088f5eaf0
Description-en: Optimized BLAS (linear algebra) library based on GotoBLAS2
 OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
 .
 Unlike Atlas, OpenBLAS provides a multiple architecture library.
 .
 All kernel will be included in the library and dynamically switched
 the best architecutre at run time.
 .
 For more information on how to rebuild locally OpenBLAS, see the section:
 "Building Optimized OpenBLAS Packages on your ARCH" in README.Debian
Description-md5: 010ad90e608009e6e8fdb04ab8387b69

The really odd thing is that import matplotlib from within a vanilla Python works normally.

@stevengj
Copy link
Member

See JuliaPy/PyCall.jl#65: some versions of numpy seem to get confused by the libopenblas library present in Julia. A workaround for now was to LD_PRELOAD the libopenblas that numpy wants.

@nowozin
Copy link

nowozin commented Sep 15, 2015

Thanks a lot Steven for your help, I will try (first attempts at copying Constantin's solution did not succeed for me), with LD_PRELOAD set I obtain errors on @pyimport matplotlib such as

julia> @pyimport matplotlib
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('/usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyExc_SystemError',)
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 180, in <module>
    from matplotlib.cbook import is_string_like
  File "/usr/lib/python2.7/dist-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 6, in <module>
    from . import multiarray

As my machine is a pretty standard install, this issue would affect all Ubuntu 15.04 users on a 64 bit machines using PyPlot, which makes this issue reasonably important in light of the upcoming 0.4 release and new users trying out Julia/PyPlot.

@stevengj
Copy link
Member

@nowozin, that sounds like JuliaPy/PyCall.jl#189, which I just fixed. Try a Pkg.update().

@nowozin
Copy link

nowozin commented Sep 16, 2015

Yes, the error reverts to the liblapack.so.3 error I reported previously, but finally I managed to get it to work on Ubuntu 15.04 x86_64 by calling Julia 0.4.0-rc1 as follows:

LD_PRELOAD=/usr/lib/atlas-base/atlas/liblapack.so.3 /opt/julia-0.4.0rc1/bin/julia

and similarly for the IPython notebook server this works:

LD_PRELOAD=/usr/lib/atlas-base/atlas/liblapack.so.3 ipython notebook

Thank you for your help tracking this down.
Unfortunately, the solution is a bit demanding on a general user.

@dehann
Copy link

dehann commented Sep 23, 2015

Hi,

I may have a related issue on 12.04, with Julia 0.4.0-rc2 and do not have a solution yet...

$ .../bin/juliarc2
...
julia> Pkg.status("PyPlot")
 - PyPlot                        2.1.0
julia> using PyPlot
ERROR: InitError: Failed to pyimport("matplotlib"): PyPlot will not work until you have a functioning matplotlib module.  PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('/home/dehann/anaconda/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so: undefined symbol: zgelsd_',)
  File "/home/dehann/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 180, in <module>
    from matplotlib.cbook import is_string_like
  File "/home/dehann/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/home/dehann/anaconda/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg

 in __init__ at /home/dehann/.julia/v0.4/PyPlot/src/PyPlot.jl:224
 in _require_from_serialized at loading.jl:84
 in _require_from_serialized at ./loading.jl:109
 in require at ./loading.jl:219
during initialization of module PyPlot

julia> versioninfo()
Julia Version 0.4.0-rc2
Commit fa52609* (2015-09-18 17:51 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Core(TM) i7-3920XM CPU @ 2.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

However, I am able to run directly in Python (Anaconda):

$ python
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, Sep 15 2015, 14:50:01) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> np.eye(4)
array([[ 1.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.],
       [ 0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  1.]])
>>> import matplotlib.pyplot as plt
>>> plt.show()

This had worked fine two months ago on Julia dev+5933 and latest packages at the time.

@stevengj
Copy link
Member

@dehann, seems to be a dup of JuliaPy/PyCall.jl#65 as above: a conflict between Julia's openblas/lapack library and the one Numpy is linking. See the LD_PRELOAD workaround mentioned there.

@stevengj
Copy link
Member

You can use Miniconda via the Conda.jl package now. Just do:

ENV["PYTHON"]=""
Pkg.update()
Pkg.build("PyCall")
using PyPlot

and it should install and use matplotlib in the "private" Julia miniconda distribution set up by Conda.

Does this fix the Numpy conflict?

@johnfgibson
Copy link

@stevengj : I'm experiencing the same problems with x86-64 Linux binary of julia-0.4.0-rc3. The suggestion above doesn't work.

gibson@timaeus$ julia-0.4.0-rc3/bin/julia    
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-rc3 (2015-09-27 20:34 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-unknown-linux-gnu

julia> ENV["PYTHON"]=""
""

julia> Pkg.update()
INFO: Updating METADATA...
INFO: Computing changes...
INFO: No packages to install, update or remove

julia> Pkg.build("PyCall")
INFO: Building PyCall
INFO: No system-wide Python was found; got the following error:
could not spawn `'' -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('VERSION'))"`: no such file or directory (ENOENT)
using the Python distribution in the Conda package
Fetching package metadata: ....
Solving package specifications: ..................
# All requested packages already installed.
# packages in environment at /home/gibson/.julia/v0.4/Conda/deps/usr:
#
numpy                     1.9.3                    py27_0  
INFO: PyCall is using /home/gibson/.julia/v0.4/Conda/deps/usr/bin/python (Python 2.7.10) at /home/gibson/.julia/v0.4/Conda/deps/usr/bin/python, libpython = /home/gibson/.julia/v0.4/Conda/deps/usr/lib/libpython2.7.so

julia> using PyPlot
INFO: Recompiling stale cache file /home/gibson/.julia/lib/v0.4/PyCall.ji for module PyCall.
INFO: Recompiling stale cache file /home/gibson/.julia/lib/v0.4/PyPlot.ji for module PyPlot.
INFO: Installing matplotlib via the Conda package...
Fetching package metadata: ....
Solving package specifications: ..................
# All requested packages already installed.
# packages in environment at /home/gibson/.julia/v0.4/Conda/deps/usr:
#
matplotlib                1.4.3                np19py27_2  
ERROR: InitError: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('cannot import name scimath',)
  File "/home/gibson/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/__init__.py", line 180, in <module>
    from matplotlib.cbook import is_string_like
  File "/home/gibson/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/home/gibson/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/home/gibson/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/gibson/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 17, in <module>
    from . import scimath as emath

 [inlined code] from /home/gibson/.julia/v0.4/PyCall/src/exception.jl:81
 in pyimport at /home/gibson/.julia/v0.4/PyCall/src/PyCall.jl:79
 in __init__ at /home/gibson/.julia/v0.4/PyPlot/src/PyPlot.jl:227
 in _require_from_serialized at loading.jl:84
 in _require_from_serialized at ./loading.jl:109
 in require at ./loading.jl:219
during initialization of module PyPlot

shell> pwd
/home/gibson/packages

julia> 

julia> versioninfo()
Julia Version 0.4.0-rc3
Commit 483d548* (2015-09-27 20:34 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Core(TM) i7-3960X CPU @ 3.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

@stevengj
Copy link
Member

stevengj commented Oct 1, 2015

@johnfgibson, did you try preloading as in JuliaPy/PyCall.jl#65 and @nowozin's comment?

@johnfgibson
Copy link

@stevengj I did, but not hard enough. Preloading both of my system's libblas.so and liblapack.so does the trick. PyPlot loads and produces plots. Many thanks for the package and the help.

LD_PRELOAD=/usr/lib64/libblas.so:/usr/lib64/liblapack.so

on openSUSE 13.2

@stevengj
Copy link
Member

stevengj commented Oct 1, 2015

Thanks for persisting. This library conflict is frustrating; I'm currently preparing a patch (OpenMathLib/OpenBLAS#656) for OpenBLAS that will fix it (once it is accepted and Julia is updated to use the new version ... but that may take a while).

@jpata
Copy link

jpata commented Oct 5, 2015

I'm getting the same error on a system where I have a system-installed python which I override with the one from anaconda. LD_PRELOAD seems to help.

export PYTHONPATH=~joosep/anaconda/lib/python2.7/site-packages/:$PYTHONPATH
export LD_LIBRARY_PATH=~joosep/anaconda/lib/python2.7/site-packages/:$LD_LIBRARY_PATH
export PATH=~joosep/anaconda/bin/:~joosep/.julia/v0.4/ROOT/:$PATH
LD_PRELOAD=/home/joosep/anaconda/lib/libopenblas.so julia
julia> ENV["PYTHON"]="/home/joosep/anaconda/bin/python"
julia> Pkg.build("PyCall")
INFO: Building PyCall
INFO: PyCall is using /home/joosep/anaconda/bin/python (Python 2.7.10) at /home/joosep/anaconda/bin/python, libpython = /home/joosep/anaconda/lib/libpython2.7.so
julia> using PyPlot
INFO: Recompiling stale cache file /home/joosep/.julia/lib/v0.4/PyCall.ji for module PyCall.
INFO: Recompiling stale cache file /home/joosep/.julia/lib/v0.4/PyPlot.ji for module PyPlot.
julia> 

@stevengj
Copy link
Member

stevengj commented Oct 5, 2015

Please try this with the latest Julia 0.4 pre-release (rc4). I think this incorporates the patch that renamed the openblas library and should (I hope!!) remove the need for the LD_PRELOAD hacks.

@johnfgibson
Copy link

@stevengj julia-0.4.0-rc4 fixes this issue for me. No more preloads. Many thanks!

@stevengj
Copy link
Member

stevengj commented Oct 6, 2015

Fantastic! Thanks to @tkelman for his help with getting this merged.

@stevengj stevengj closed this as completed Oct 6, 2015
@jpata
Copy link

jpata commented Oct 6, 2015

I still seem to be getting

julia> using PyPlot
pyimport exception was: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('/home/joosep/anaconda/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so: undefined symbol: zgelsd_',)
  File "/home/joosep/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 180, in <module>

on Version 0.4.0-rc4+1 (2015-10-04 05:59 UTC) if I don't preload libopenblas.so.

I rebuilt the julia binary with a clean openblas and did a rebuild of PyCall and PyPlot, but to no avail.

@stevengj
Copy link
Member

stevengj commented Oct 6, 2015

@jpata, you might want to make sure that there is no libopenblas.so hanging around inside your Julia directory (in <julia-path>/usr/lib) from previous compilations. Especially if you installed Julia with make install, you might have Julia's old libopenblas.so in a directory like /usr/local/lib where the runtime linker can find it. (Nowadays, Julia's openblas is called libopenblas64_.so, so it is safe to delete any libopenblas.so that was not the one that came with Anaconda.)

@jpata
Copy link

jpata commented Oct 6, 2015

Thanks, that was it. After

$ rm usr/lib/libopenblas.so
$ rm usr/lib/libopenblas.so.0

importing PyPlot seems to work. Great to have this fixed!

@bisraelsen
Copy link

I am still getting this error using a fresh install of 0.4.2:

julia> versioninfo()
Julia Version 0.4.2
Commit bb73f34 (2015-12-06 21:47 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: liblapack.so.3
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

I have tried removing the libopenblas.so, and LD_PRELOAD method, and making sure PyCall is updated. I am also using the Conda installation of PyPlot.

I don't think I missed anything in the thread... Any further ideas?

@wangg12
Copy link

wangg12 commented Jan 15, 2017

ENV["PYTHON"]="the result of `which python`"
# 
# Pkg.update()
Pkg.build("PyCall")
using PyPlot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants