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

Image loading fails in IJulia notebook #51

Closed
jakesnell opened this issue Dec 18, 2013 · 14 comments
Closed

Image loading fails in IJulia notebook #51

jakesnell opened this issue Dec 18, 2013 · 14 comments

Comments

@jakesnell
Copy link

I get the following error when loading an image in the IJulia notebook:

convert: unexpected end-of-file `-': No such file or directory @ error/rgb.c/ReadRGBImage/231.

See http://nbviewer.ipython.org/gist/jakesnell/8026978 for the code.

The same snippet works in the REPL:

julia> using ImageView, Images, TestImages

julia> img = testimage("mandrill")
RGB Image with:
  data: 3x512x512 Array{Uint8,3}
  properties:
    limits: (0x00,0xff)
    colordim: 1
    spatialorder:  x y
    colorspace: RGB

julia> display(img, pixelspacing=[1,1])
(ImageCanvas,ImageSlice2d: zoom = BoundingBox(0.0,512.0,0.0,512.0))

Not sure if this is a bug in Images.jl or if my IJulia installation is somehow broken. Any ideas?

@timholy
Copy link
Member

timholy commented Dec 18, 2013

Works for me. I did update the package just this morning, which changed a lot of I/O; which version are you running?

@jakesnell
Copy link
Author

I was using v0.2.17. After upgrading to v0.2.18, I now get a different error in IJulia (REPL still works fine):

In [2]: img = testimage("mandrill")
unable to load module `/usr/lib/ImageMagick-6.8.7//modules-Q16HDRI/coders/png.la': file not found @ error/module.c/OpenModule/1277
 in error at error.jl:21
 in error at /home/jake/.julia/Images/src/ioformats/libmagickwand.jl:102
 in setimageformat at /home/jake/.julia/Images/src/ioformats/libmagickwand.jl:209
 in getblob at /home/jake/.julia/Images/src/ioformats/libmagickwand.jl:128
 in writemime at /home/jake/.julia/Images/src/io.jl:161
 in base64 at base64.jl:125
 in display_dict at /home/jake/.julia/IJulia/src/execute_request.jl:30

I do have png.la:

$ ls -l /usr/lib/ImageMagick-6.8.7/modules-Q16HDRI/coders/png.la 
-rwxr-xr-x 1 root root 1.1K Dec 17 15:11 /usr/lib/ImageMagick-6.8.7/modules-Q16HDRI/coders/png.la

but somehow Julia's getting an extra slash in the path.

The libMagickWand dependency did fail for me when I updated Images.jl to v0.2.18 (I'm using Arch Linux). To work around this, I manually created a symbolic link at libMagickWand.so, pointing to libMagickWand-6.Q16HDRI.so. Manually building v0.2.18 then seemed to work just fine.

Here's what my /usr/lib now looks like:

$ ls -l /usr/lib | grep -i wand
lrwxrwxrwx  1 root root    30 Mar 11  2013 libGraphicsMagickWand.so -> libGraphicsMagickWand.so.2.6.0
lrwxrwxrwx  1 root root    30 Mar 11  2013 libGraphicsMagickWand.so.2 -> libGraphicsMagickWand.so.2.6.0
-rwxr-xr-x  1 root root  176K Mar 11  2013 libGraphicsMagickWand.so.2.6.0
lrwxrwxrwx  1 root root    32 Dec 17 15:11 libMagickWand-6.Q16HDRI.so -> libMagickWand-6.Q16HDRI.so.1.0.0
lrwxrwxrwx  1 root root    32 Dec 17 15:11 libMagickWand-6.Q16HDRI.so.1 -> libMagickWand-6.Q16HDRI.so.1.0.0
-rwxr-xr-x  1 root root  1.2M Dec 17 15:11 libMagickWand-6.Q16HDRI.so.1.0.0
lrwxrwxrwx  1 root root    26 Dec 18 17:10 libMagickWand.so -> libMagickWand-6.Q16HDRI.so

@timholy
Copy link
Member

timholy commented Dec 19, 2013

With regards to the latter point, would you be willing to (1) delete your symlink and (2) test the io branch (Pkg.checkout("Images", "io")) to see if it automatically finds your library now? ImageMagick seems to have a whole zoo of potential names on different systems.

With regards to the more serious issue: I find it strange that a C library might behave differently in IJulia vs the REPL. However, "mandrill" is stored as a TIFF rather than PNG, so perhaps it's a format issue. If you try img = testimage("mountainstream"), what happens?

Similar issues:
http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=11643&sid=5266ea65a7c53c292fb20ef30daff0b5&start=15#p105247

Homebrew/legacy-homebrew#14325

@jakesnell
Copy link
Author

Without changing the symlink, "mountainstream" fails in both the REPL and IJulia with

ERROR: unable to load module `/usr/lib/ImageMagick-6.8.7//modules-Q16HDRI/coders/png.la': file not found @ error/module.c/OpenModule/1277

"mandrill" works in the REPL but fails in IJulia.

Here's what happens after I delete the symlink:

julia> Pkg.checkout("Images", "io")
INFO: Checking out Images io...
INFO: Pulling Images latest io...
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> io

ERROR: failed process: Process(`git --work-tree=/home/jake/.julia/Images --git-dir=/home/jake/.julia/Images/.git pull -q --ff-only`, ProcessExited(1)) [1]
 in pipeline_error at process.jl:476
 in run at process.jl:453
 in run at git.jl:24
 in anonymous at no file:160
 in transact at git.jl:81
 in _checkout at pkg/entry.jl:154
 in checkout at pkg/entry.jl:169
 in anonymous at pkg/dir.jl:25
 in cd at file.jl:22
 in cd at pkg/dir.jl:25

git st in ~/.julia/Images shows that I'm on branch io:

$ pwd
/home/jake/.julia/Images
$ git st
# On branch io
nothing to commit, working directory clean

Building Images fails:

julia> Pkg.build("Images")
INFO: Building Images
===========================================================[ ERROR: Images ]============================================================

None of the selected providers can install dependency libMagickWand
at /home/jake/.julia/Images/deps/build.jl:32

========================================================================================================================================

============================================================[ BUILD ERRORS ]============================================================

WARNING: Images had build errors.

 - packages with build errors remain installed in /home/jake/.julia
 - build a package and all its dependencies with `Pkg.build(pkg)`
 - build a single package by running its `deps/build.jl` script

========================================================================================================================================

Here's what I get when running deps/build.jl:

$ julia ~/.julia/Images/deps/build.jl 
ERROR: None of the selected providers can install dependency libMagickWand
 in error at error.jl:21
 in satisfy! at /home/jake/.julia/BinDeps/src/dependencies.jl:439
 in satisfy! at /home/jake/.julia/BinDeps/src/dependencies.jl:421
 in anonymous at /home/jake/.julia/BinDeps/src/dependencies.jl:450
 in include at boot.jl:238
at /home/jake/.julia/Images/deps/build.jl:32

@timholy
Copy link
Member

timholy commented Dec 19, 2013

That's very useful. Several points:

  • Since you already have ImageMagick installed, building isn't actually necessary (the only thing the build does is install ImageMagick).
  • It would be nice if the build script wouldn't barf. It looks like Arch linux uses "pacman"; currently BinDeps does not support pacman, but it doesn't look too hard to add new package managers. @loladiro might be able to offer some advice, but I presume this is something better done by you than him since you can test it and he might not be able to do so. Then, inserting a pacman build instruction in Images would be trivial.
  • @StefanKarpinski, that Pkg.checkout error above seems new to me. Anything we can do about that?
  • With regards to the issue that started this: the difference between REPL and IJulia turns out to be incidental. What's happening is that IJulia is calling writemime to display the image, but the REPL is not (because the REPL isn't graphical). My implementation of writemime encodes the image as a PNG, and that's exposing the fact that libMagickWand is having trouble with PNGs. Since "mandrill" is a tiff, it loads fine (in either), and the bug in IJulia comes at the next step. Since "mountainstream" is a PNG, you have problems from the outset. So do any further testing with "mountainstream", and you shouldn't need to test both the REPL and IJulia until you want to verify that everything has been fixed.

I'm not certain what the issue is with libMagickWand and PNGs, but from those links I posted above you're clearly not alone in this problem. To me it seems like an ArchLinux problem, but one we might have to cope with. Can you run the command-line convert to format "mandrill" as a PNG?

@StefanKarpinski
Copy link

The error is happening because the io branch isn't setup to be able to pull from anywhere. I'm not sure how clever we should get here since this is getting into territory where we can easily make things more confusing rather than less.

@jakesnell
Copy link
Author

That's interesting about writemime. It struck me as a bit odd that IJulia would behave differently from the REPL but that makes more sense now. At the moment, neither TIFF nor PNG works (presumably due to the deleted symlink):

julia> using ImageView, Images, TestImages
WARNING: ImageMagick utilities not found. Install for more file format support.

julia> img = testimage("mountainstream")
ERROR: error compiling imread: error compiling imread: error compiling MagickWand: could not load module libMagickWand: libMagickWand: cannot open shared object file: No such file or directory
 in testimage at /home/jake/.julia/ImageView/test/testimages.jl:29

I'm happy to try adding pacman to BinDeps; hopefully that will help fix things.

@timholy
Copy link
Member

timholy commented Dec 19, 2013

@StefanKarpinski, agreed one shouldn't get too clever. I suspect that package authors will fairly frequently ask users to test specific new-feature or hotfix branches. Would it be appropriate to add some Pkg documentation about how to check out brand-new branches?

@jakesnell, the message

WARNING: ImageMagick utilities not found. Install for more file format support.

means it's still not finding the library without the symlink. Are you on the real io branch? The key lines are here. If not, the accepted answer should get you there. (It's possible you'll have to delete your own io branch, if you created one.)

Finding the library is a separate issue from enhancing BinDeps; BinDeps only affects what happens when build.jl is run, which only happens when you first install, or upgrade, Images.

Thanks for sticking with this!

@StefanKarpinski
Copy link

@StefanKarpinski, agreed one shouldn't get too clever. I suspect that package authors will fairly frequently ask users to test specific new-feature or hotfix branches. Would it be appropriate to add some Pkg documentation about how to check out brand-new branches?

I'm ok with doing the right thing here, I just don't know what it is. Do you have an example case where I can try checking out a different branch? I'd actually like for Pkg.checkout(pkg, branch) to automatically create local branches for remotes and set them up for tracking.

@timholy
Copy link
Member

timholy commented Dec 19, 2013

@StefanKarpinski, you could try the io branch of Images.

@jakesnell
Copy link
Author

@jakesnell, the message

WARNING: ImageMagick utilities not found. Install for more file format support.

means it's still not finding the library without the symlink. Are you on the real io branch? The key lines are here. If not, the accepted answer should get you there. (It's possible you'll have to delete your own io branch, if you created one.)

Aha! You are 100% right. I wasn't in fact on the real io branch (thanks for bearing with me, I'm still a bit new to the finer points of git). The io branch makes the warning go away but I still get the strange double-slash error. I still have no idea what could be causing that.

julia> using ImageView, Images, TestImages

julia> img = testimage("mountainstream")
ERROR: unable to load module `/usr/lib/ImageMagick-6.8.7//modules-Q16HDRI/coders/png.la': file not found @ error/module.c/OpenModule/1277
 in error at error.jl:21
 in error at /home/jake/.julia/Images/src/ioformats/libmagickwand.jl:100
 in readimage at /home/jake/.julia/Images/src/ioformats/libmagickwand.jl:142
 in imread at /home/jake/.julia/Images/src/io.jl:173
 in imread at /home/jake/.julia/Images/src/io.jl:99
 in testimage at /home/jake/.julia/ImageView/test/testimages.jl:29

@jakesnell
Copy link
Author

I'm starting to think this is a straight-up ImageMagick (and maybe also libpng) problem. I'll investigate and get back soon.

@jakesnell
Copy link
Author

Turns out that I had an old version of libpng on my system and ImageMagick was having a hard time talking to it. I updated libpng and now everything works like a charm as long as I stay on the io branch. I'm still planning on adding pacman to BinDeps, but I'll close this issue since my original problem is now solved. Thanks for your help Tim and for a great library. I'm looking forward to getting back to using it again!

@timholy
Copy link
Member

timholy commented Dec 20, 2013

Glad you figured it out.

I merged the io branch and tagged a new version.

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

3 participants