ranger icon indicating copy to clipboard operation
ranger copied to clipboard

Using ueberzug with conda environment

Open AniAggarwal opened this issue 3 years ago • 9 comments
trafficstars

Runtime Environment

  • Operating system and version: Ubuntu 20.04 LTS
  • Terminal emulator and version: Gnome Terminal 3.36.2
  • Python version: 3.8 (Conda)
  • Ranger version/commit: 1.9.3
  • Locale: en_US.UTF-8

Current Behavior

Running ranger while in a conda env from terminal doesn't allow ueberzug to display images. Note: my-env does NOT have ueberzug installed in it. $ conda activate my-env $ ranger [Error 2] No such file or directory: 'ueberzug' when hovering over image

Running ranger from the env ueberzug where ueberzug is installed in works as expected.

Expected Behavior + Context

I have added my conda env which contains ueberzug to path in my .bashrc as follows. Neither of the two attempts below works. export PATH="/home/ani/miniconda3/envs/ueberzug/bin/ueberzug:$PATH" export PATH="/home/ani/miniconda3/envs/ueberzug/bin/:$PATH"

This is in my rc.fonf: set preview_images_method ueberzug

I would like to just add the above line to my .bashrc and specify the path to ueberzug in my rc.conf so that it uses that ueberzug. This is important to me because, when working in a conda env on a project, I need to deactivate it every time to use ranger with ueberzug. I cannot install ueberzug in every env because of package conflicts (defeating the point of envs in the first place).

Possible Solutions

If supplied a path to a venv for the preview images method, use that. Would builiding ueberzug from source help? Maybe I can build in such a way that its not tied to a python env? If so, any ideas on how to do so?

Steps to reproduce

  1. Create a conda env (a normal venv may work too, untested)
  2. Activate that env and install ueberzug there (via pip install ueberzug)
  3. Deactivate it
  4. Add that env's bin to path
  5. Launch ranger in an env that does not have ueberzug installed
  6. Try to view image

AniAggarwal avatar Feb 23 '22 21:02 AniAggarwal

Hi

Did you install ueberzug using conda or pip in the conda environment? What is the output of the command which ueberzug

It's working fine at my end. I have installed ueberzug using pip.

You can find my configuration files here.

manujchandra avatar Feb 28 '22 14:02 manujchandra

Ueberzug was installed via pip in the conda environment.

Output of which ueberzug when in my base env (which does not have ueberzug installed): /home/ani/miniconda3/bin/ueberzug Output of which ueberzug when in my ueberzug env (which does have ueberzug installed): /home/ani/miniconda3/envs/ueberzug/bin/ueberzug Maybe some change needs to be made here so ranger knows which one to use?

I wasn't able to find much in your config files, but I might not know where to look (beginner here).

I should note that it works fine for me when my ueberzug environment is activated. If I'm in another environment, it doesn't work and ranger throws errors (shown below).

When in my ueberzug conda env: Screenshot from 2022-03-03 07-01-46

When in my base env (which does not have ueberzug installed): Screenshot from 2022-03-03 07-04-08

AniAggarwal avatar Mar 03 '22 15:03 AniAggarwal

Hi,

It seems its not a ueberzug problem. Following observations:

  1. You have ueberzug installed in both your base environment and ueberzug environment. Remove ueberzug from your base environment
  2. Do not call your environment ueberzug. Call it something else like ueber or util
  3. Ranger is able to find ueberzug but if you look closely, you are getting the error "no module named 'attr'. Maybe try a pip install attr in your ueberzug environment? Try if this works.

If not, this is the workflow I use, and it has always worked for me on fedora (and also arch):

  1. Install Anaconda
  2. sudo dnf install gtk3-devel (or arch equivalent)
  3. Create an environment called util
  4. Activate util
  5. Install pip in it by conda install -c anaconda pip
  6. Then do a pip install ueberzug
  7. deactivate the util environment
  8. which ueberzug to check if its available system wide (it should)
  9. Now, image previews works from any environment

manujchandra avatar Mar 04 '22 08:03 manujchandra

Thanks for the details instructions! Installing attr did not work

I followed your instructions, and installed the dev gtk3 like so as I'm on Ubuntu: sudo apt install libgtk-3-dev In my new utils env:

(utils) $ which ueberzug
/home/ani/miniconda3/envs/utils/bin/ueberzug

In my base env ueberzug is not found.

(base) $ which ueberzug
(base) $

Ranger with ueberzug works fine when uitls is activated but does not when in the base env. I should note that I don't receive any errors not when trying to view an image in the base env. Also, the issue of images not displaying centered was resolved (not one I had brought up though), presumably thanks to gtk3-dev.

AniAggarwal avatar Mar 04 '22 14:03 AniAggarwal

Hi,

I am assuming when you run ranger from base you dont get any errors but it does not work.

Try restarting your computer. The reason why its not working could be because ueberzug is not available system wide. Maybe after restarting it would take effect.

If restarting does not work, try to add '/home/ani/miniconda3/envs/utils/bin/ueberzug' to your paths. This way, ueberzug will be available system wide and ranger should be able to find it.

Just for reference, I am on Fedora and this is what my output looks like:

🐚(base) manuj@shelter ~ $ which ueberzug
/home/manuj/anaconda3/envs/util/bin/ueberzug

and

🐚(base) manuj@shelter ~ $ conda activate util
🐚(util) manuj@shelter ~ $ which ueberzug
/home/manuj/anaconda3/envs/util/bin/ueberzug

Note that the steps outlined in the previous post work for me out of the box on Fedora and Endeavour OS without any special configuration from my end.

manujchandra avatar Mar 05 '22 06:03 manujchandra

I know this is not an ideal solution, but worst case scenario, install ueberzug in all your environments.

manujchandra avatar Mar 05 '22 06:03 manujchandra

I think the problem here is that ranger uses the Ueberzug Python module, not the bin/ueberzug script. The simplest way around this issue may be to either change the shebang in the ranger script to use the absolute path to your ueberzug env's Python or aliasing ranger to path/to/your/ueberzug/env/bin/python3 path/to/ranger.

toonn avatar May 13 '22 14:05 toonn

That didn't seem to work unfortunately. I changed the ranger's shebang to my utils conda env which contains both ranger-fm and ueberzug. All works as expected when I have activated the environment, but if I try to use ueberzug with ranger while in my base env, images don't show. Screenshot from 2022-05-14 22-10-00

AniAggarwal avatar May 15 '22 05:05 AniAggarwal

I think the problem here is that ranger uses the Ueberzug Python module, not the bin/ueberzug script.

Is that correct? It looks like it's calling the bin: https://github.com/ranger/ranger/blob/391f061cb0b0cfa8266c0651f2a6d948f22e01dd/ranger/ext/img_display.py#L749

markus-bauer avatar May 15 '22 14:05 markus-bauer