Forum Archive

Can I use the pyphen module?

macmacmac

I installed the hyphenation module pyphen from pyphen.org using pip install Pyphen in stash. When I run the simple test below I get a TypeError:coercing to Unicode:need... The module should be 100% pure Python.

import pyphen
dic = pyphen.Pyphen(lang='en_EN')
print( dic.wrap('community', 4)  )
Webmaster4o

@macmacmac Since it's supposed to be "100% pure Python with no dependencies," why don't you try manually downloading and unzipping the package, just in case it's a problem with StaSh. After that, if you still have the problem, maybe you should file a bug report to the developers of Pyphen. If you don't still have the problem after installing it manually, file a bug report with @ywangd, the developer of StaSh.

ywangd

Restart Pythonista should fix this (double click home button and swipe up to remove Pythonista from the task list).

It may due to a previous failed pip command. I am not sure and I cannot reproduce it. But by looking at the code of Pyphen. It tries to import pkg_resources which is part of setuptools. These packages are mocked by stash pip and should be removed once pip finishes. Maybe somewhere in previous runs, somehow they are leaked.

macmacmac

@ywangd: Thanks a lot for the simple solution. Restarting did the trick. Thanks also for writing stash.

@Webmaster4o : Thanks for the useful advise. For future problems: How do I download, unzip and install a module manually using Pythonista?

dgelessus
  1. wget <download URL>
  2. If it's a zip file, unzip <filename>, if it's a tar.gz file, tar -xzf <filename>
  3. Inside the extracted folder, you'll usually find a folder (or sometimes a single Python script) with the same name as the module - that is what you need to move/copy to site-packages.
Webmaster4o

@macmacmac

@dgelessus gives a good approach using StaSh. I usually just find the file in Safari, and then use the share sheet to "Run Pythonista Script" and then I've got a script that downloads the URL.

macmacmac

Thanks for both methods. Very useful to know.