Closed paulwyszynski closed 3 months ago
Hi @paulwyszynski, thank you for reporting.
I haven't tested kitty-scrollback.nvim with image.nvim yet. Could you share your Neovim config repo or a snippet of your image.nvim config setup so that I can try and reproduce?
Hi @mikesmithgh
sure here you can find my image.lua file for image.nvim https://github.com/paulwyszynski/dotfiles/blob/master/nvim/lua/plugins/image.lua
In the plugins folder is my entire plugins setup with all the plugins I use. I also use lazyvim as my setup http://www.lazyvim.org/
Hey @paulwyszynski, I am unable to get image.nvim
working on my machine.
I get the error same error as you see in kitty-scrollback.nvim.
image.nvim: magick rock not found, please install it and restart your editor. Error: "...y/luarocks.nvim/.rocks/share/lua/5.1/magick/wand/lib.lua:220: Failed to load ImageMagick (MagickWand)"
I see this in the README of image.nvim:
brew install imagemagick
$(brew --prefix)/lib
to
DYLD_LIBRARY_PATH
by adding something like
export DYLD_LIBRARY_PATH="$(brew --prefix)/lib:$DYLD_LIBRARY_PATH"
to your shell profile (probably .zshrc
or .bashrc
)I tried following those steps but it didn't work for me. Do you have some configuration in your .bash/zsh/fish for this?
I am guessing kitty-scrollback.nvim is having trouble finding some environment variables.
Hi @mikesmithgh I added the DYLD_LIBRARY_PATH to my .zshrc file, but I also had to add luarocks to my image.lua file. Only after that it worked for me. Now I'm getting this error only when I start kitty-scrollback.
Thanks @paulwyszynski , I figured out what was happening. I have a wrapper script around nvim
and it was losing DYLD_LIBRARY_PATH
in my case. I am able to reproduce and see what is happening.
kitty-scrollback.nvim is unable to find DYLD_LIBRARY_PATH
due to MacOS quirks. See https://sw.kovidgoyal.net/kitty/faq/#how-do-i-specify-command-line-options-for-kitty-on-macos
Apple does not want you to use command line options with GUI applications. To workaround that limitation, kitty will read command line options from the file
/macos-launch-services-cmdline when it is launched from the GUI, i.e. by clicking the kitty application icon or using open -a kitty. Note that this file is only read when running via the GUI.
You have two options to fix this:
cond
field.Example:
{
'3rd/image.nvim',
cond = vim.env.KITTY_SCROLLBACK_NVIM ~= 'true',
opts = {},
},
KITTY_SCROLLBACK_NVIM
.DYLD_LIBRARY_PATH
to <kitty config dir>/macos-launch-services-cmdline
.~/.config/kitty/macos-launch-services-cmdline
:
--override env=DYLD_LIBRARY_PATH="/opt/homebrew/lib"
Let me know how it goes and I'll plan to update the Wiki https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki#recommended-configurations-for-other-plugins
Hi @mikesmithgh
thank you for your time and investigation! I actually prefer the 2nd solution. But the path does not exist for me. When I echo this echo $(brew --prefix)/lib
, it shows me this path here: /usr/local/lib
. But even with this path it still shows the same error when starting kitty-scrollback (with kitty closed completely and reopen).
I added the file macos-launch-services-cmdline
to my kitty config folder with the following content:
--override env=DYLD_LIBRARY_PATH="$(brew --prefix)/lib"
The 1st solution with the cond field works for me.
If you have any suggestions for the 2nd solution with env path, let me know!
Thanks so far!
Could you try the path /usr/local/lib
instead of the brew prefix command? I don't know if Kitty can resolve the $(brew --prefix)
syntax in macos-launch-services-cmdline
.
Tried it already, same issue. Now the solution with the cond field works for kitty-scrollback but now im getting the same error if I open the default editor (which in my case is neovim) in lazygit. This images plugin starts to get annoying 😂. I think the 2nd solution would be more sustainable.
@paulwyszynski Actually, could you try using the env var DYLD_FALLBACK_LIBRARY_PATH
? I came across a stack overflow question that recommends that instead of DYLD_LIBRARY_PATH
.
If that doesn't work, then some follow up:
How did you install ImageMagick ?
When I was troubleshooting this, I found that magick LuaRock is using the command pkg-config --cflags --libs MagickWand
to try and find information about the dynamic library. DYLD_LIBRARY_PATH
is trying to tell it where to look for the libMagick dylib
.
Try
pkg-config --cflags --libs MagickWand
cd $(brew --prefix)/lib
ls -la | grep -E 'libMagick.*dylib'
You should see something similar to -lMagickWand-7.Q16HDRI
from the results of pkg-config
and libMagick++-7.Q16HDRI.dylib
when you grep
in the homebrew directory.
If you don't see a file similar to libMagick++-7.Q16HDRI.dylib
in /usr/local/lib
, then that is the wrong path. You basically need to try and set DYLD_LIBRARY_PATH
to the directory that contains something like libMagick++-7.Q16HDRI.dylib
.
If you don't see the dylib
file you may need to track it down and update DYLD_LIBRARY_PATH
.
If it is there, and you have macos-launch-services-cmdline
set correctly. Then something else may be happening.
You can also try the commands :=vim.env.DYLD_LIBRARY_PATH
and :=vim.env.DYLD_FALLBACK_LIBRARY_PATH
in Neovim to see what values they are set to in your Neovim session. One thing to note, I wasn't getting values for DYLD_LIBRARY_PATH
even though I set it. But, could see it for DYLD_FALLBACK_LIBRARY_PATH
.
@mikesmithgh
I installed it like so:
brew install imagemagick
both entries added:
--override env=DYLD_LIBRARY_PATH="/usr/local/lib"
--override env=DYLD_FALLBACK_LIBRARY_PATH="/usr/local/lib"
Same issue.
this is my output here
pkg-config --cflags --libs MagickWand
-Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -I/usr/local/Cellar/imagemagick/7.1.1-36/include/ImageMagick-7 -L/usr/local/Cellar/imagemagick/7.1.1-36/lib -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI
❯ cd $(brew --prefix)/lib
❯ ls -la | grep -E 'libMagick.*dylib'
lrwxr-xr-x 1 paulwyszynski admin 64 Aug 3 12:17 libMagick++-7.Q16HDRI.5.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagick++-7.Q16HDRI.5.dylib
lrwxr-xr-x 1 paulwyszynski admin 62 Aug 3 12:17 libMagick++-7.Q16HDRI.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagick++-7.Q16HDRI.dylib
lrwxr-xr-x 1 paulwyszynski admin 67 Aug 3 12:17 libMagickCore-7.Q16HDRI.10.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagickCore-7.Q16HDRI.10.dylib
lrwxr-xr-x 1 paulwyszynski admin 64 Aug 3 12:17 libMagickCore-7.Q16HDRI.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagickCore-7.Q16HDRI.dylib
lrwxr-xr-x 1 paulwyszynski admin 67 Aug 3 12:17 libMagickWand-7.Q16HDRI.10.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagickWand-7.Q16HDRI.10.dylib
lrwxr-xr-x 1 paulwyszynski admin 64 Aug 3 12:17 libMagickWand-7.Q16HDRI.dylib -> ../Cellar/imagemagick/7.1.1-36/lib/libMagickWand-7.Q16HDRI.dylib
in neovim only this is found:
:=vim.env.DYLD_LIBRARY_PATH
which is /usr/local/lib
the fallback is nil in neovim:
:=vim.env.DYLD_FALLBACK_LIBRARY_PATH
which is nil
hmm.. I'm not sure why it isn't working.
Okay, one last (hacky) thing you can do 😂
There is an open issue https://github.com/3rd/image.nvim/issues/91#issuecomment-2025287226 related, seems like others have similar issues.
The workaround is to hardcode the full path to libMagickWand-7.Q16HDRI.dylib in the magick luarock.
The file should be at ~/.local/share/nvim/lazy/luarocks.nvim/.rocks/share/lua/5.1/magick/wand/lib.lua
assuming you have the same setup. I think you do since we are using lazy.nvim.
You can replace https://github.com/leafo/magick/blob/6971fa700c4d392130492a3925344b51c7cc54aa/magick/wand/lib.lua#L220-L231
lib = try_to_load("MagickWand", function()
local lname = get_flags():match("-l(MagickWand[^%s]*)")
local suffix
if ffi.os == "OSX" then
suffix = ".dylib"
elseif ffi.os == "Windows" then
suffix = ".dll"
else
suffix = ".so"
end
return lname and "lib" .. lname .. suffix
end)
with
lib = try_to_load("/usr/local/lib/libMagickWand-7.Q16HDRI.dylib")
This hardcodes the filepath, so not great, but at least a workaround.
I came across this post as well, but the path does not exist for me, also installing lua 5.1 via brew is not an option anymore. My luarocks folder looks like this:
If it's working for you I think we had a different installation approach, because all I did, is like installing imagemagick via brew and the content added to my image.lua file in plugins folder.
That is weird about the error, path's non-existent:
image.nvim: magick rock not found, please install it and restart your editor. Error: "...y/luarocks.nvim/.rocks/share/lua/5.1/magick/wand/lib.lua:220: Failed to load ImageMagick (MagickWand
)"
@paulwyszynski hmm what about the this path?
~/.luarocks/share/lua/5.1/magick/wand/lib.lua
also FYI for brew you can use luajit for 5.1.
brew install luajit
I think luarocks.nvim is doing some magic under the hood to make it happen 😄
Yeah i think so too, the luarocks dependency makes some vodoo.
The path you mentioned is not available for me, but I found this one:
/Users/paulwyszynski/.luarocks/lib/luarocks/rocks-5.1
but this one has just some manifest file in this path 🤷♂️
And installing luajit will fix it?
Interesting. Has image.nvim worked for you in just a normal Neovim session. Have you actually been able to render an image?
I am not sure where your lua rock is being saved on your machine.
Since you are using lazy.nvim and luarocks.nvim, I assumed it was ~/.local/share/nvim/lazy/luarocks.nvim/.rocks/share/lua/5.1/magick
. That is where it is installed for me.
The other approach using luajit
and manually installing via luarocks --local --lua-version=5.1 install magick
puts it ~/.luarocks/share/lua/5.1/magick/
on my machine.
If it is working for you, then I am just not sure where it is on your filesystem. If it is not working, you could try running this in Neovim:
:Lazy build luarocks.nvim
and it should install the rock to ~/.local/share/nvim/lazy/luarocks.nvim/.rocks/share/lua/5.1/magick
Ok I removed everything and installed from scratch, now I can see the rocks folder and this workaround https://github.com/mikesmithgh/kitty-scrollback.nvim/issues/261#issuecomment-2278917413 seems to work for now.
Thank you! Hope they fix this in the future.
@paulwyszynski awesome! Glad the workaround worked at least. I'll plan to add a note to the wiki and close this issue out 👍
Hey, I don't if it's correct to address this here or in image.nvim. So I'm using kitty and image.nvim https://github.com/3rd/image.nvim and according to the setup it works for me (If you follow the setup for MacOS). But when I'm trying to load the scrollback in nvim it show the nvim start screen with this error:
image.nvim: magick rock not found, please install it and restart your editor. Error: "...y/luarocks.nvim/.rocks/share/lua/5.1/magick/wand/lib.lua:220: Failed to load ImageMagick (MagickWand )"
Loading the scrollback in nvim also takes like ~15 sec. This error doesn't appear when I open nvim normally. I guess this has something to do with my plugins setup.