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

Some issue with pillow on the termux #1

Open
jonasprokopf opened this issue Nov 4, 2024 · 3 comments
Open

Some issue with pillow on the termux #1

jonasprokopf opened this issue Nov 4, 2024 · 3 comments

Comments

@jonasprokopf
Copy link

jonasprokopf commented Nov 4, 2024

Hey, I just tried your script, but unfortunately it didn't work for me. It might be due to my android/termux environment? Anyways. Here's my console:

.../substack-to-epub-main/substack-to-epub-main $ python archive.py                                               Found 12 articles on https://thespouter.substack.com/    Added content for article https://thespouter.substack.com/p/the-isa-upanisad                                      Added content for article https://thespouter.substack.com/p/frack-5-the-feeding-frenzy                            Added content for article https://thespouter.substack.com/p/vaseline                                              Added content for article https://thespouter.substack.com/p/iix-fuel-is-coming                                    Added content for article https://thespouter.substack.com/p/fuel-is                                               Added content for article https://thespouter.substack.com/p/a-fuel-is-land                                        Added content for article https://thespouter.substack.com/p/b-fuel-is-a-raw-material-and-a-commodity
Added content for article https://thespouter.substack.com/p/c-fuel-is-money                                       Added content for article https://thespouter.substack.com/p/d-i-fuel-is-a-part-of-the-means-of                    Added content for article https://thespouter.substack.com/p/d-ii-fuel-is-a-part-of-the-technical                  Added content for article https://thespouter.substack.com/p/e-fuel-is-labor                                       Added content for article https://thespouter.substack.com/p/e-ii-fuel-is-sometimes-socially-necessary
Added the contents of 12 articles to the database        Added article "f2024-04-23T20:40:55.113Z: The Īśa Upaniṣad" to ebook
Added article "f2024-05-02T17:34:55.392Z: FRACK 5: Strategic Provocation of LNG Spot Price via War in Ukraine " to ebook                                                   Added article "f2024-05-29T19:00:47.285Z: Vaseline" to ebook
Added article "f2024-09-16T18:29:14.244Z: iix. Fuel Is... Coming" to ebook
Added article "f2024-09-18T19:02:02.172Z: Fuel Is..." to ebook
Added article "f2024-09-23T18:46:09.514Z: A) Fuel Is Land" to ebook                                               Added article "f2024-09-26T18:45:57.987Z: B) Fuel Is a Raw Material & a Commodity" to ebook
Added article "f2024-09-30T18:34:32.807Z: C) Fuel Is Money" to ebook
Added article "f2024-10-03T17:00:20.828Z: D) i. Fuel is a Part of the Means of Production" to ebook               Added article "f2024-10-07T18:35:47.184Z: D) ii. Fuel is a Part of the Technical Apparatus for Increasing Productivity" to ebook                                           Added article "f2024-10-10T18:59:31.661Z: E) i. Fuel Is Labor" to ebook                                           Added article "f2024-10-13T23:35:40.313Z: E) ii. Fuel is Only Sometimes Socially Necessary Labor" to ebook
Traceback (most recent call last):                         File "/storage/emulated/0/Download/substack-to-epub-main/substack-to-epub-main/archive.py", line 224, in <module>
    main()                                                 File "/storage/emulated/0/Download/substack-to-epub-main/substack-to-epub-main/archive.py", line 217, in main       book.create_epub("./", book_title)                     File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/epub.py", line 410, in create_epub
    create_cover()                                         File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/epub.py", line 370, in create_cover     cover = get_cover_image(title=self.title, author=self.creator, publisher=self.publisher)                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                        File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/cover.py", line 32, in get_cover_image
    title_font = ImageFont.truetype(COVER_FONT_PATH, 96)                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/ImageFont.py", line 996, in truetype
    return freetype(font)                                           ^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/ImageFont.py", line 993, in freetype         return FreeTypeFont(font, size, index, encoding, layout_engine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                 File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/ImageFont.py", line 220, in __init__
    if core.HAVE_RAQM:                                          ^^^^^^^^^^^^^^                                      File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/_util.py", line 19, in __getattr__
    raise self.ex                                          File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/ImageFont.py", line 58, in <module>          from . import _imagingft as core
ImportError: cannot import name '_imagingft' from 'PIL' (/data/data/com.termux/files/usr/lib/python3.12/site-packages/PIL/__init__.py). Did you mean: '_imaging'?          .../substack-to-epub-main/substack-to-epub-main $

(excuse the bad formatting, dunno what's up with that)

And here's my .env:

SUBSTACK_SID_COOKIE="123123"
SUBSTACK_BASE_URL="https://thespouter.substack.com/"
SUBSTACK_NEWSLETTER_NAME="The Spouter"
SUBSTACK_NEWSLETTER_AUTHOR="The Spouter"

Thanks for the script and thank you for reading my issue!

@carterworks
Copy link
Owner

carterworks commented Nov 4, 2024

Yes, it looks like an issue that appears when using Pillow in termux. There are some related issues in the PIL repo.

One of them suggest installing the termux pillow package

pkg install python-pillow

Let me know if that fails to resolve the issue.

@jonasprokopf
Copy link
Author

Yes, it looks like an issue that appears when using Pillow in termux. There are some related issues in the PIL repo.

One of them suggest installing the termux pillow package

pkg install python-pillow

Let me know if that fails to resolve the issue.

Unfortunately, this throws a new error. From an uneducated glance, it looks like your script can't call the termix package.

python archive.py
Traceback (most recent call last):                         File "/storage/emulated/0/Download/substack-to-epub-main/substack-to-epub-main/archive.py", line 9, in <module>     import xml2epub                                        File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/__init__.py", line 4, in <module>       from .epub import Epub
  File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/epub.py", line 31, in <module>
    from .cover import get_cover_image                     File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/xml2epub/cover.py", line 11, in <module>
    from PIL import Image, ImageFont, ImageDraw          ImportError: cannot import name 'Image' from 'PIL' (unknown location)

If you are (understandibly) uninterested in helping me resolve an issue i have on my end that is unrelated to your script, would you maybe be so kind to convert the substack from the .env included in my initial post for me? I promise, I'm only going to ask for this one substack^^

@carterworks carterworks reopened this Nov 4, 2024
@carterworks
Copy link
Owner

carterworks commented Nov 4, 2024

I think that error comes up when there is a naming collision i.e. two dependencies named PIL.

Here's the workflow to resolve that naming collision, I think

  1. Install project deps (which you have already done): python3 -m pip install -r requirements.txt
  2. Uninstall the installed Pillow: python3 -m pip uninstall PIL; python3 -m pip uninstall Pillow
  3. Install the termux-compiled Pillow: pkg install python-pillow
  4. Run the script: python3 archive.py

Reference: https://stackoverflow.com/questions/26505958/why-cant-python-import-image-from-pil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants