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

Having trouble installing libraqm #8232

Closed
HectorsitoXD opened this issue Jul 14, 2024 · 25 comments
Closed

Having trouble installing libraqm #8232

HectorsitoXD opened this issue Jul 14, 2024 · 25 comments
Labels
Font Rendering Installation Usually a problem with …

Comments

@HectorsitoXD
Copy link

HectorsitoXD commented Jul 14, 2024

What did you do?

I am trying to install libraqm. I'm using Replit and I managed to install pillow, but when I try to use kern or liga as font features i am prompted an "Unable to use features without libraqm" error, so I tried to install it using "pip install libraqm" but that didn't work. I know very little about python and programming in general, so please be specific with me.

What did you expect to happen?

I expect the libraqm lib to be installed with no problem but it turned out to be more complex than a command in the shell.

What actually happened?

~/$ pip install libraqm
ERROR: Could not find a version that satisfies the requirement libraqm (from versions: none)
ERROR: No matching distribution found for libraqm

What are your OS, Python and Pillow versions?

  • OS: Replit
  • Python: I think Python 3
  • Pillow: I assume I installed the last Pillow version
Please paste here the output of running:

python3 -m PIL.report
or
python3 -m PIL --report

Or the output of the following Python code:

from PIL import report
# or
from PIL import features
features.pilinfo(supported_formats=False)

image

code goes here

import discord
from discord import app_commands
from discord.ext import commands
from PIL import Image, ImageDraw, ImageFont

token = '(token)'
bot = commands.Bot(command_prefix = ".", intents = discord.Intents.all())

from PIL import features
print (features.check('raqm'))

@bot.event
async def on_ready():
  print("Hello wolrd!")
  try:
    synced = await bot.tree.sync()
    print(f"Synced {len(synced)} command(s)")
  except Exception as e:
    print(e)

@bot.tree.command(name = "type", description = "Send an image of your text in BA")
@app_commands.describe(text = "Text to send")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)

async def type(interaction: discord.Interaction, text: str):
  image = Image.new('RGBA', (1, 1), (0, 0, 0, 0))
  draw = ImageDraw.Draw(image)
  font = ImageFont.truetype("font.ttf", 50)

  x = int(draw.textlength(text, font=font, font_size=50, features=None))

  lines = 0
  if x > 500:
    list = text.split()
    print(list)
    chunk = ""
    new = ""
    lenghts = []
    c = -1
    for i in list:
      c += 1
      chunk = chunk + i
      print(chunk)
      x = int(draw.textlength(chunk, font=font, font_size=50, features=None))
      print(x)
      if x > 500:
        lenghts.append(x)
        print(lenghts)
        new = new + chunk + "\n"
        print(new)
        chunk = ""
        print(list.index(i))
        print(len(list))
        if c != len(list) - 1:
          lines = lines + 1
      else:
        chunk = chunk + " "
    new = new + chunk
    text = new
    lenghts.append(x)
    x = max(lenghts)
  print(lines)
  image = image.resize((x,50+44*lines))
  draw = ImageDraw.Draw(image)
  draw.multiline_text((0,0), text, (255,255,255), font=font, features=None)
  image.save("text.png")

  await interaction.response.send_message(
    file = discord.File("text.png")
    )

bot.run(token)

The code runs perfect as it is, but when I change features=None to features="kern" or features="liga" it prompts this error:
image

@HectorsitoXD
Copy link
Author

The code is a bit of a mess because it's for a discord bot that gets text and sends it using a font that is designed to write in a language that me and some friends made up. The issue here is that that language needs to use ligatures to work, but I can't do that without libraqm and I can't get it installed

@radarhere
Copy link
Member

Hi. pip is for installing Python libraries, and libraqm is not a Python library. So that's why pip fails to install it.

I notice 'nix' in your output. Does that mean you're using nixpkgs? If so, https://search.nixos.org/packages?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=raqm might help you install libraqm. After that, try uninstalling and installing Pillow again.

@HectorsitoXD
Copy link
Author

I'll try, thanks

@HectorsitoXD
Copy link
Author

image

@radarhere
Copy link
Member

@laggron42 as the other person who most recently created a nix issue, are you able to offer any guidance?

@HectorsitoXD
Copy link
Author

oh it says: couldn't get nix env building nix env: exit status 1

@nulano nulano added Installation Usually a problem with … Font Rendering labels Jul 14, 2024
@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

This appears so be Replit's documentation for installing packages: https://docs.replit.com/replit-workspace/dependency-management#:~:text=To%20install%20additional%20packages%20in,replit%20file.

It seems that you may be able to install system packages by using the System (Advanced) tab: https://docs.replit.com/replit-workspace/dependency-management#advanced-configuration

Perhaps you should try to install libraqm there.

However, from the PIL.report output it seems to me you may be using one of our binary wheels (I am not entirely certain, but all of the version numbers match the latest release). If that is the case, you do not need to install libraqm, but only its dependency fribidi: https://search.nixos.org/packages?channel=24.05&show=fribidi&from=0&size=50&sort=relevance&type=packages&query=fribidi

@HectorsitoXD
Copy link
Author

then how can I install fribidi?

@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

then how can I install fribidi?

I'd suggest the System (Advanced) tab mentioned in the documentation I linked above.

@nulano nulano closed this as completed Jul 14, 2024
@nulano nulano reopened this Jul 14, 2024
@HectorsitoXD
Copy link
Author

HectorsitoXD commented Jul 14, 2024

I've installed it I think, but still not working. Replit AI tells me to install a pillow wheel with libraqm in it. I don't even know what a wheel is 😅, but is that possible to do? I just want ligatures to be able to be rendered 😫

@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

Replit AI tells me to install a pillow wheel with libraqm in it. I don't even know what a wheel is 😅, but is that possible to do?

You'd need to build your own which is very likely to be more complicated.

@HectorsitoXD
Copy link
Author

hmmm, and do you know what else can I do? I could use something else than replit, maybe I could try using vsc, I just use replit cause is very convenient to work with

@HectorsitoXD
Copy link
Author

HectorsitoXD commented Jul 14, 2024

I have this in the code:

from PIL import features
print(features.check('raqm'))

and every time I run it it prompts False
I tried restarting but everything looks the same...

@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

Assuming you installed it, I would expect RAQM support ok to show up if you rerun the report command. But since you say it is still not working, I assume it is still failing to detect it.

Have you tried restarting the replit instance or something like that?

I'm also wondering if there is an environment variable missing.
Although https://ask.replit.com/t/automatically-installing-python-system-dependencies/74996/13 suggests it should automatically be set correctly, perhaps that is not working - you could check by providing the output of the set command, or perhaps running strace python3 -m PIL.report (warning: this will produce a very long output).

You could also consider asking for help on the Replit forum.


maybe I could try using vsc

Do you mean VS Code? I think that could be easier since it would be running on your system (as I understand it Replit runs in the cloud, with limited documentation on their system). We probably have more experience here helping people install libraqm/fribidi in a local environment.

@HectorsitoXD
Copy link
Author

Yes, VS Code, I have it installed, so if you could teach me how to install libraqm or fribidi or whatever I have to install in order for it work I could also try it there

@HectorsitoXD
Copy link
Author

image
Also saying "False" in visual studio code

@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

Please paste here the output of running:

python3 -m PIL.report
or
python3 -m PIL --report

Or the output of the following Python code:

from PIL import report
# or
from PIL import features
features.pilinfo(supported_formats=False)

Please do this in VS Code then.

@HectorsitoXD
Copy link
Author

HectorsitoXD commented Jul 14, 2024

--------------------------------------------------------------------
Pillow 10.4.0
Python 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is D:\Alpha\Python\BAT\.venv\Scripts\python.exe
Environment Python files loaded from D:\Alpha\Python\BAT\.venv
System Python files loaded from C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0
--------------------------------------------------------------------
Python Pillow modules loaded from D:\Alpha\Python\BAT\.venv\Lib\site-packages\PIL
Binary Pillow modules loaded from D:\Alpha\Python\BAT\.venv\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
-------------------------------------------------------------------- 

@HectorsitoXD
Copy link
Author

RAQM is marked as not installed as well

@nulano
Copy link
Contributor

nulano commented Jul 14, 2024

It looks like you are using UWP Python, so this is going to be a bit more complicated than usual on Windows.

First, download fribidi-windows-AMD64 and extract fribidi.dll from the zip file.

Now you need to place it in a location that will be searched by Windows; because you are using UWP Python that is the Standard search order for packaged apps.

Typically I would recommend using the "The folder the calling process was loaded from (the executable's folder)" entry, but because of Windows Store security restrictions, you would need to have TrustedInstaller rights to do that.

There are only three other options:

  • "The system folder (%SystemRoot%\system32)", this is most likely C:\Windows\System32.

    This is not a great idea since it could cause issues with other applications, but is the only option that works without special Python code.

  • "Loaded-module list."

    Put fribidi.dll in any other directory (e.g. C:\path\to\fribidi.dll), and add the following code before the from PIL import ... line:

    import ctypes
    fribidi = ctypes.CDLL(r"C:\path\to\fribidi.dll")
    
    # import PIL modules only after the above lines, e.g.:
    from PIL import report
  • "Paths explicitly added with the AddDllDirectory function."

    Put fribidi.dll in any other directory (e.g. C:\path\to\fribidi.dll), and add the following code before the from PIL import ... line:

    import os
    os.add_dll_directory(r"C:\path\to")
    
    # import PIL modules only after the above lines, e.g.:
    from PIL import report

If you weren't using UWP Python, you could also add the code of either of the last two options to your site.py file, but that is also within the protected area.

@HectorsitoXD
Copy link
Author

I don't really get it... I tried the two last options (you said the first one could cause problems) but just nothing happens, I run the code and everything looks the same. I didn't know I was using UWP python so I wouldn't mind changing my Python version

@HectorsitoXD
Copy link
Author

HectorsitoXD commented Jul 15, 2024

Solution

Update: Someone in a discord server found a solution (I think it's literally what you told me but I didn't quite get). Basically I had to uninstall microsoft store's Python and install it through the official web. Then I just had to add the fribidi.dll file downloaded here fribidi-windows-AMD64 in the folder python was installed in.

@nulano
Copy link
Contributor

nulano commented Jul 15, 2024

I think it's literally what you told me but I didn't quite get

I only hinted at it, but did not say it explicitly. 😄

I wouldn't mind changing my Python version

(and I couldn't reply to this comment with the full explanation because I wasn't at my computer)


I don't really get it... I tried the two last options (you said the first one could cause problems) but just nothing happens, I run the code and everything looks the same.

FWIW I did test that exact code with UWP Python 3.10 (i.e. same as what you had) and it worked, so I suspect you had something importing Pillow before those lines.

But I suppose it doesn't matter anymore since you have regular Python installed now.

@anitoanto
Copy link

Will future standard Pillow installation include libraqm and fribidi by default, or is there a better solution than the manual workaround?

@radarhere
Copy link
Member

There has been a recent suggestion of switching to SheenBiDi instead of FriBiDi - #8497 (comment). I expect that would improve the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Font Rendering Installation Usually a problem with …
Projects
None yet
Development

No branches or pull requests

4 participants