cewe2pdf icon indicating copy to clipboard operation
cewe2pdf copied to clipboard

FontTools.ttLib unknown location

Open boggiz opened this issue 1 year ago • 7 comments

Hi, Former user of the version 'mcf2pdf by Florian Albretch' I am very happy to have found this program which should allow the taking into account of the new functionalities of Cewe.

But, at the launch, I encounter this problem that I do not understand:

Synology NAS DS718+ python 3.8.12

import cewe2pdf Traceback (most recent call last): File "", line 1, in File "/volume1/homes/xxxxx/Informatique/Python/cewe2pdf-master/cewe2pdf.py", line 76, in from fontTools import ttLib ImportError: cannot import name 'ttLib' from 'fontTools' (unknown location)

Yet fontTools-4.53.1 was correctly installed and the 'ttLib' directory exist:

root@NAS-DS718:/usr/lib/python3.8/site-packages/fontTools/ttLib# ls init.py removeOverlaps.py standardGlyphOrder.py ttGlyphSet.py macUtils.py reorderGlyphs.py tables ttVisitor.py main.py scaleUpem.py ttCollection.py woff2.py pycache sfnt.py ttFont.py

Can someone help me to fix this error?

boggiz avatar Sep 18 '24 08:09 boggiz

Not really my area of competence, but I think you might want to check your python search path. Maybe in an interactive python setting: import sys sys.path and make sure the python search path looks good. I think you modify it on Linux using the PYTHONPATH environment variable. Install the packages from requirements.txt with pip. Otherwise ... you're going to need at least Python 3.9, as mentioned here: https://github.com/bash0/cewe2pdf/issues/180 And I'm a bit surprised by your import statement for cewe2pdf.py. That's not how I use it. Take a look at the readme, https://github.com/bash0/cewe2pdf/blob/master/README.md#using-the-program

On Wed, 18 Sept 2024 at 10:18, boggiz @.***> wrote:

Hi, Former user of the version 'mcf2pdf by Florian Albretch' I am very happy to have found this program which should allow the taking into account of the new functionalities of Cewe.

But, at the launch, I encounter this problem that I do not understand:

Synology NAS DS718+ python 3.8.12

import cewe2pdf Traceback (most recent call last): File "", line 1, in File "/volume1/homes/xxxxx/Informatique/Python/cewe2pdf-master/cewe2pdf.py", line 76, in from fontTools import ttLib ImportError: cannot import name 'ttLib' from 'fontTools' (unknown location)

Yet fonttools-4.53.1 was correctly installed and the 'ttLib' directory exist:

@.***:/usr/lib/python3.8/site-packages/fontTools/ttLib# ls init.py removeOverlaps.py standardGlyphOrder.py ttGlyphSet.py macUtils.py reorderGlyphs.py tables ttVisitor.py main.py scaleUpem.py ttCollection.py woff2.py pycache sfnt.py ttFont.py

Can someone help me to fix this error?

— Reply to this email directly, view it on GitHub https://github.com/bash0/cewe2pdf/issues/184, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBIDKNCKO73A4SQXRM7QD3ZXEZOFAVCNFSM6AAAAABONDZ4ECVHI2DSMVQWIX3LMV43ASLTON2WKOZSGUZTGMBUHAZDANA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AnEnglishmanInNorway avatar Sep 18 '24 13:09 AnEnglishmanInNorway

Sorry for my late reply, thank you for your response. Whether on Windows 10 or Linux when I position myself in the cewe2pdf.py directory the command: python3.9 cewe2pdf.py c:/toto systematically executes with the error ttLib line 76. For testing, in case of error, it is faster to launch import cewe2pdf from python rather than switching from Shell <=> Python without stopping.

About PATH os.listdir() image

If I continue in the tree structure I find my files: os.listdir('Informatique/Python/cewe2pdf-master') image

export PYTHONPATH=Informatique/Python/cewe2pdf-master python3.9 cewe2pdf.py c:/toto image

The working directory did not change ! image

How to change it ? I tried with PYTHONSTARTUP and a bash without success.

What to do now ?

boggiz avatar Sep 27 '24 13:09 boggiz

I'm not quite sure how to help you further. The images in your last comment are unfortunately too small to do any more than guess what they might say. But I've tried a couple of things on my machine to check that things work here. Some initial comments:

  1. It might be worth getting the current version of the code. In the base version the import that you are having trouble with is on line 81, not line 76, so you're clearly a little behind the front (though I doubt that your problems are caused by that)
  2. My strategy is always to have the cewe2pdf directory as the current directory, and to specify the path of the .mcf or .mcfx album file on the command line. And I always have a cewe2pdf.ini and an additional_fonts.txt file beside my album file so that they take precedence over the ones in the cewe2pdf directory.

So that I have something close to your environment I have

  • Started Ubuntu on my Windows machine, with Python 3.10 installed, as described here.
  • With the cewe2pdf directory as my current directory, installed the packages we need with pip install -r requirements.txt.

I then ran python3 cewe2pdf.py tests/unittest_fotobook.mcfx. This produced a .pdf for the unittest album. There were several errors in the resulting pdf because of missing fonts, backgrounds, etc but the code processed the entire file with no "python" errors, and in particular no failure to import ttLib

I'm attaching a log of what happened in my shell as I did all this - perhaps examining that will allow you to see where your setup is different to mine: UbuntuLog.txt

Just for interest, I also checked my path and import of ttLib:

me@mypc:/mnt/d/users/.../github/cewe2pdf$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
>>> import sys
>>> sys.path
['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/petes/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages']
>>> import inspect
>>> from fontTools import ttLib
>>> inspect.getmodule(ttLib)
<module 'fontTools.ttLib' from '/home/petes/.local/lib/python3.10/site-packages/fontTools/ttLib/__init__.py'>

AnEnglishmanInNorway avatar Sep 27 '24 17:09 AnEnglishmanInNorway

Thx for your explanations. I increased the size of the images for better readability. I will try again ...

boggiz avatar Sep 28 '24 07:09 boggiz

Thanks, now your images are readable. Your problem is surely PYTHONPATH. This is supposed to be a search path (a list of directories) for Python to find things, as you can see from the sys.path array in my comment - and not the location of your files, as your third image shows. Searching for "python path" on the web will get you lots of information about it, here is one such site

Quite why you have trouble in the first place I can't say - on my machine, both in the native Windows environment and in the Linux subsystem, I have never had to do anything special to get the search path right, it has just happened "magically" in the background as part of the installation of Python and the packages that I have installed.

AnEnglishmanInNorway avatar Sep 28 '24 10:09 AnEnglishmanInNorway

I'm wondering whether this is still an open issue, or whether @boggiz has managed to get his version up and rolling?

AnEnglishmanInNorway avatar Oct 31 '24 20:10 AnEnglishmanInNorway

No the problem remains open but I haven't found the time to continue testing at the moment. Sorry

boggiz avatar Oct 31 '24 22:10 boggiz

Has this become irrelevant after nearly 6 months, @boggiz?

AnEnglishmanInNorway avatar Apr 14 '25 11:04 AnEnglishmanInNorway

Close after lack of input. By all means reopen if it becomes relevant again, there might be something different in your environment that we should take account of

AnEnglishmanInNorway avatar Jun 10 '25 08:06 AnEnglishmanInNorway