Problem using anyascii

27 views
Skip to first unread message

Julie N

unread,
Mar 1, 2023, 3:02:06 AM3/1/23
to PyInstaller
Hi all,

I have a fairly simple script that uses anyascii (https://pypi.org/project/anyascii/) and works fine when run in a development environment.

However, when built into an executable with PyInstaller, I start seeing problems.

First, an exception was thrown saying the module 'anyascii._data' couldn't be found. Looking in the installation, there is a subfolder of this name which appears to hold the datafiles used to do the Unicode to ascii transliteration.

Adding

from anyascii import _data

to my script got rid of  the exception, but anyascii still doesn't work -- it replaces the Unicode characters with nothing instead of the desired substitutions, that is, it still can't seem to find its datafiles!

So I have tried to add lots of variations of the following to my command line:

--add-data "[path to Python installation]\Python\Python37\Lib\site-packages\anyascii\_data\*;anyascii._data"

...but still no luck! Any advice about how to incorporate these datafiles so anyascii can find them?

Googling, of course, has yielded nothing. :( I'm also building with --debug=imports, but the output hasn't yielded anything helpful either.

Any advice about how to correctly incorporate these datafiles into my executable?

Thanks!

Julie

Eric Fahlgren

unread,
Mar 1, 2023, 12:12:08 PM3/1/23
to pyins...@googlegroups.com
Hi Julie,

Looking at the source for anyascii, it uses importlib.resources to grab those binaries, so I think it should be able to just grab them as you're trying to do (if it anyascii were just doing "open...read", that would probably result in some different strategy being needed).

In any case, when you run your pyinstaller command, have you noted that it produces a file "xxx.spec" (xxx is your exe name)?  To make this easier (easiest?), start using that file instead of jamming a bunch of stuff on the command line.

First, make sure you have a good spec, assuming your old command line looked like:

$ pyinstaller xxx.py --a-bunch-of-stuff

you'll now use this in its place:

$ pyinstaller xxx.spec

as "xxx.spec" contains all the settings from the command line.  Edit that file and look for "hiddenimports" in the "Analysis" block, I think that is the most likely candidate to solve this.  Change it to something like

   hiddenimports = ['anyascii._data.000', 'anyascii._data.001'],

and try the build, see if it coughs up any errors or reports that yes indeed it's including those data files.  I'm sort of educated-guessing on the names listed there, but it should be something very close to that.  If it works, then write some code in the .spec file that looks grossly like (yes, the is hacky, but it should give you the idea):

from glob import glob
from os.path import split
includes = []
for data_file in glob('wherever/they/live/anyascii/_data/*'):
    dir, name = split(data_file)
    if len(name) == 3:  # <-- The super hacky part...
        includes.append('anyascii._data.%s' % name)

then change that hiddenimports to 

   hiddenimports = includes,

Run "pyinstaller xxx.spec" and see if it works.

Eric

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/361386f0-c39d-47e6-8374-1cfaac6e0a7en%40googlegroups.com.

Julie N

unread,
Mar 2, 2023, 3:18:32 PM3/2/23
to PyInstaller
Hi Eric,

Thanks so much for your reply! I did know about the spec file, but did not quite understand how to really use it.

So I tried your suggested approach, but alas while it built  and ran without complaint, I get the same results.

None of the anyascii._data.xxx imports showed up in the debug output, so perhaps these shouldn't be treated as hidden imports? I'll try a few other approaches...but in any case using the spec file as you suggested is a much better idea!

Thanks again, and of course any other ideas are very welcome!

Julie

Julie N

unread,
Mar 2, 2023, 5:58:06 PM3/2/23
to PyInstaller
Hey, I got this working!

Here's what I did in the spec file:

datas=[('[path to Python installation]\\Lib\\site-packages\\anyascii\\_data\\*', 'anyascii\\_data')]

...and now it's building, running, and working as expected!

Thanks again to Eric for getting me pointed in the right direction!

Julie

Reply all
Reply to author
Forward
0 new messages