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

Problem with Kitty on OSX #1499

Closed
EvanCarroll opened this issue Mar 20, 2019 · 20 comments
Closed

Problem with Kitty on OSX #1499

EvanCarroll opened this issue Mar 20, 2019 · 20 comments

Comments

@EvanCarroll
Copy link

I'm using Kitty on osx and (from the kitty docs)

kitty +kitten icat ~/Downloads/image.png

does in fact work, but having

set preview_images true
set preview_images_method kitty

Inside of rc.conf does not make ranger render the images. I'm using ranger 1.9.2 and Kitty 0.13.3 (both installed with brew)

@EvanCarroll
Copy link
Author

I tried upgrading ranger to 3.7.2. I'm getting the same issue (Feb 12, 2019)

@toonn
Copy link
Member

toonn commented Mar 20, 2019

It's probably your TERM setting. By default it should be xterm-kitty and ranger refuses to display images with the kitty method unless TERM contains or ends with kitty.

If you changed it to xterm-256color for ssh/tmux, I feel the pain : )
I don't mess with TERM but I call ssh like this env TERM=xterm-256color ssh user@host....

@toonn
Copy link
Member

toonn commented Mar 20, 2019

Oh, or maybe it's because you need PIL/pillow.

@EvanCarroll
Copy link
Author

EvanCarroll commented Mar 27, 2019

This issue was caused because I didn't have imagemagick which was required. I installed that and it worked. I guess the brew doesn't currently require imagemagick. It'll give the right error when you open up a single picture. My suggestiopn when debugging this is to open a picture and not use the nav to get to the image.

Perhaps it should be more verbose.

@toonn
Copy link
Member

toonn commented Mar 28, 2019

That's weird. @mark-dawn did intend to implement a wrapper for ImageMagick to use it as an alternative dep to pillow in the future. But that hasn't happened yet so it's weird installing ImageMagick solved any problem. We do use ImageMagick to automatically rotate images. Maybe all the images you've tried had to be rotated? Could you download some random png somewhere, the ranger logo for example, and see whether that'd preview without ImageMagick.

@evb-gh
Copy link

evb-gh commented Apr 23, 2019

I had the same problem as user @EvanCarroll. Installing Pillow, enabling set preview_images true and setting set preview_images_method kitty din't work. I would get the Image previews in kitty require PIL (pillow)" error. I noticed that ranger would use the system version of python (from /usr/bin/python) instead of the version installed by brew (in /usr/local/bin/python). To fix this I had to edit ranger.py and change:

#!/usr/bin/python -O

to

#!/usr/local/bin/python -O

Is there a different way to have ranger default to the brew installation of python?

@toonn
Copy link
Member

toonn commented Apr 23, 2019

Normally scripts would use #!/usr/bin/env python but shebangs only allow one command and one argument so that'd prohibit us from passing -O. I think the only recourse is to alter the install script to rip out the shebang and replace it with the path of the python interpreter that's running the script. Thanks for reporting this btw, it's one of those confusing issues we don't always think of.

To anyone who wants an easier way to test if they installed pillow/any module for the interpreter that's actually running ranger, start ranger and then :eval import pillow or whatever module you're expecting. If it's not installed correctly that'll error and ranger'll show the message in the status bar in red, otherwise it'll show nothing.

@toonn
Copy link
Member

toonn commented Apr 23, 2019

@EvanCarroll, can you confirm whether unrotated images did/did not preview without imagemagick? And could you check whether you actually installed pillow for the right python? Easily checked by running eval import pillow, that'll error if it's not installed for the python that runs ranger, you would have to get back to the situation where previews didn't work though, maybe uninstalling imagemagick is enough?

@ebv-gh, that's actually a sorta common mistake people make, installing deps for the wrong python. Normally the shebang'd be #!/usr/bin/env python but it's impossible to pass the -O flag because linux only allows one command and one argument. A wrapper script won't work because mac os doesn't allow scripts to be interpreters in shebangs. I'm a little bit stumped on this tbh. This problem surfaces in nix packaging too, there the flag is simply dropped but that means users get assertion errors they shouldn't.

@ashleyharvey
Copy link

I had the same problem as user @EvanCarroll. Installing Pillow, enabling set preview_images true and setting set preview_images_method kitty din't work. I would get the Image previews in kitty require PIL (pillow)" error. I noticed that ranger would use the system version of python (from /usr/bin/python) instead of the version installed by brew (in /usr/local/bin/python). To fix this I had to edit ranger.py and change:

#!/usr/bin/python -O

to

#!/usr/local/bin/python -O

Is there a different way to have ranger default to the brew installation of python?

Thanks for this .. I've just gone through this nightmare myself and this is what fixed it for me.

@toonn toonn added the bug label Aug 24, 2019
@ggsalas
Copy link

ggsalas commented Jul 9, 2020

I had the same problem as user @EvanCarroll. Installing Pillow, enabling set preview_images true and setting set preview_images_method kitty din't work. I would get the Image previews in kitty require PIL (pillow)" error. I noticed that ranger would use the system version of python (from /usr/bin/python) instead of the version installed by brew (in /usr/local/bin/python). To fix this I had to edit ranger.py and change:

#!/usr/bin/python -O

to

#!/usr/local/bin/python -O

Is there a different way to have ranger default to the brew installation of python?

Works for me too. There is a way to add this change on the config instead edit ranger file? Thanks!

@toonn toonn added this to the v1.9.4 milestone Jul 10, 2020
@oncomouse
Copy link

I also had this problem. I solved it by installing ranger-fm through brew's version of pip, which is annoying, but it did work.

@CrazyGriferman
Copy link

I also had this problem. I solved it by installing ranger-fm through brew's version of pip, which is annoying, but it did work.

Thanks! It just solves the problem.

@toonn
Copy link
Member

toonn commented Jun 19, 2022

Looks like Homebrew packagers picked up on this issue and it got fixed on their side 🎉

@toonn toonn closed this as completed Jun 19, 2022
@wansingcheng

This comment was marked as spam.

@stevenwalton
Copy link

I think this is still broken. I'm on an M2 using kitty and zsh. kitty +kitten icat example.png works just fine but ranger doesn't. Everything is installed with brew

System:

[ steven ] [~] > uname -a                                                                                                                                                  []
Darwin Swordfish 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112 arm64
[ steven ] [~] > zsh --version                                                                                                                                             []
zsh 5.9 (x86_64-apple-darwin22.0)
[ steven ] [~] > kitty --version                                                                                                                                           []
kitty 0.27.1 created by Kovid Goyal
[ steven ] [~] > ranger --version                                                                                                                                          []
ranger version: ranger 1.9.3
Python version: 3.11.4 (main, Jun 20 2023, 17:23:00) [Clang 14.0.3 (clang-1403.0.22.14.1)]
Locale: en_US.UTF-8
[ steven ] [~] > conda --version                                                                                                                                           []
conda 23.5.0
[ steven ] [~] > python --version                                                                                                                                          []
Python 3.11.4
[ steven ] [~] > python -c "import PIL"                                                                                                                                    []
[ steven ] [~] > # success
[ steven ] [~] > /usr/bin/python3 -c "import PIL"                                                                                                                          []
[ steven ] [~] > # success

Looks like Homebrew packagers picked up on this issue and it got fixed on their side 🎉

Looking back at homebrew we have

 depends_on "python@3.11"

  def python
    Formula["python@3.11"].opt_libexec/"bin/python"
  end

But the M2's system python is

[ steven ] [~] > /usr/bin/python3 --version                                                                                                                                []
Python 3.9.6

Even upgrading my conda version doesn't work (was on 3.10 before)

[ steven ] [~] > python --version                                                                                                                                          []
Python 3.11.4

I tried installing Pillow into both to no success. $PATH has the conda version first and running :eval import PIL and then hitting W I see (parsed because no copy paste)

Message Log:
ranger 1.9.3
Python version 3.11.4 (...) [Clang 14.0.3 (...)]
...
ERRO Notification: The error `No module named 'PIL'` was created...

I thought maybe the issue was bash since I am using zsh and the log shows a bash looking $PS, but bash also imports PIL just fine. The python version displayed by ranger also updated with my conda upgrade so I'm extra confused here. It seems that ranger is loading the conda python but unable to get the imports. In fact, I can't import any non-native modules. So looks like this is the disconnect.

I'm kinda at a loss here as to what else it could be. Any ideas?

@toonn
Copy link
Member

toonn commented Aug 17, 2023

@stevenwalton, I suspect Homebrew has installed Python 3.11.4 too, to satisfy the dependency so it's not actually using the Python provided by Conda. Run :eval import sys; print(sys.executable) from Ranger to find out what interpreter it is really running.

@stevenwalton
Copy link

@stevenwalton, I suspect Homebrew has installed Python 3.11.4 too, to satisfy the dependency so it's not actually using the Python provided by Conda. Run :eval import sys; print(sys.executable) from Ranger to find out what interpreter it is really running.

This gives me /opt/homebrew/opt/python@3.11/bin/python3.11. But note that ls -l `which python` gives me /opt/homebrew/anaconda3/bin/python -> python3.10. Note that /opt/homebrew/opt/python@3.11 -> ../Cellar/python@3.11/3.11.4_1.

So of course /opt/homebrew/opt/python@3.11/bin/python3.11 -m pip install Pillow does actually resolve the issue, but I think this is going to lead to common user confusion. The user is not interacting with that version of python (seriously, how many times do we need to install python?). I think this could be best resolved through checking the user's environment. Going back to the homebrew package it's worth noting that this is not checked for. The formula just explicitly installs python3.11, and is likely going to result in a unique installation of python for many users. This isn't an acceptable solution when it is quite easy to check for existing python installations. I am quite skeptical to believe that ranger specifically needs 3.11 and would be surprising if we are required to always have the latest version.

So I am still quite certain that this is a bug, not a feature nor user error.

@toonn
Copy link
Member

toonn commented Aug 23, 2023

I agree, but it's a bug in the Homebrew packaging, not Ranger.

@stevenwalton
Copy link

Issue taken to Homebrew.

Worth also noting that I do not see Pillow in the requirements, here, on the README, though the current error is sufficient to give the user the correct solution.

I do also believe it is in the ranger team's interest to resolve package manager issues when the package manager is sufficiently popular and is an expected method of installation for users. Though I understand this is not an officially endorsed method I think it would benefit users.

@toonn
Copy link
Member

toonn commented Aug 24, 2023

The problem is one of workload. There's a lot of package managers out there. We have to rely on volunteer maintainers for them. I'm not sure this is on the Homebrew maintainers either though. Pillow is not really a Ranger dependency, it's only needed for the Kitty and Ueberzug preview methods.

Pillow's mentioned in the man page but it is conspicuously missing from the README, thanks for pointing this out.

toonn added a commit to toonn/ranger that referenced this issue Aug 24, 2023
Addresses a [comment from ranger#1499][1] pointing out the lack of mention of
the Pillow dependency in the README.

[1]: ranger#1499 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants