mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
398 stars 80 forks source link

PyInstaller and Python-arabic-reshaper (Python 2.7) #12

Closed BobAchgill closed 7 years ago

BobAchgill commented 7 years ago

I am trying to use PyInstaller to put an exe wrapper around my code that imports Python-arabic-reshaper, but I got this error,

Traceback (most recent call last): File "<string>", line 20, in <module> File "C:\Users\Ownerc\Downloads\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\lo ader\pyi_importers.py", line 270, in load_module File "C:\Python27\build\hhr_video_maker - Copy\out00-PYZ.pyz\arabic_reshaper", line 1, in <module> File "C:\Users\Ownerc\Downloads\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\lo ader\pyi_importers.py", line 270, in load_module File "C:\Python27\build\hhr_video_maker - Copy\out00-PYZ.pyz\arabic_reshaper.a rabic_reshaper", line 1377, in <module> File "C:\Python27\build\hhr_video_maker - Copy\out00-PYZ.pyz\arabic_reshaper.a rabic_reshaper", line 1248, in __init__ ValueError: Invalid configuration: A section with the name ArabicReshaper was no t found

The config file I was using is default-config.ini, I have also had configparser package installed.

Thank you,

Just an update... We made a very simple Python 2.7 script that uses the Python-arabic-reshaper library. The script runs successfully but fails when packaged into an exe using Pyinstaller.

The Pyinstaller (tool that packages the Python script and libraries into an exe) documentation says suggests to use the archive viewer to see what library files may have been missed in being included in the exe package.

Below is the archive viewer output that shows all the assets included in the pyinstaller "exe" package. Can you identify any missing files from the exe package that the Python-arabic-reshaper needs in order to run?

E:\TAMU>python "E:\Anaconda2\Lib\site-packages\PyInstaller\utils\cliutils\archive_viewer.py" "e:\TAMU\dist\bob_test_1.exe"
 pos, length, uncompressed, iscompressed, type, name
[(0, 170, 235, 1, 'm', u'struct'),
 (170, 1153, 2704, 1, 'm', u'pyimod01_os_path'),
 (1323, 4222, 11804, 1, 'm', u'pyimod02_archive'),
 (5545, 6034, 18956, 1, 'm', u'pyimod03_importers'),
 (11579, 1589, 4450, 1, 's', u'pyiboot01_bootstrap'),
 (13168, 347, 504, 1, 's', u'bob_test_1'),
 (13515, 48403, 89416, 1, 'b', u'VCRUNTIME140.dll'),
 (61918, 39529, 87552, 1, 'b', u'_bz2.pyd'),
 (101447, 624405, 1443840, 1, 'b', u'_hashlib.pyd'),
 (725852, 76667, 146432, 1, 'b', u'_lzma.pyd'),
 (802519, 28814, 66048, 1, 'b', u'_socket.pyd'),
 (831333, 888894, 2045440, 1, 'b', u'_ssl.pyd'),
 (1720227, 10439, 19136, 1, 'b', u'api-ms-win-core-console-l1-1-0.dll'),
 (1730666, 10253, 18624, 1, 'b', u'api-ms-win-core-datetime-l1-1-0.dll'),
 (1740919, 10265, 18624, 1, 'b', u'api-ms-win-core-debug-l1-1-0.dll'),
 (1751184, 10322, 18624, 1, 'b', u'api-ms-win-core-errorhandling-l1-1-0.dll'),
 (1761506, 11406, 22208, 1, 'b', u'api-ms-win-core-file-l1-1-0.dll'),
 (1772912, 10289, 18624, 1, 'b', u'api-ms-win-core-file-l1-2-0.dll'),
 (1783201, 10419, 18624, 1, 'b', u'api-ms-win-core-file-l2-1-0.dll'),
 (1793620, 10290, 18624, 1, 'b', u'api-ms-win-core-handle-l1-1-0.dll'),
 (1803910, 10469, 19136, 1, 'b', u'api-ms-win-core-heap-l1-1-0.dll'),
 (1814379, 10302, 18624, 1, 'b', u'api-ms-win-core-interlocked-l1-1-0.dll'),
 (1824681, 10532, 19136, 1, 'b', u'api-ms-win-core-libraryloader-l1-1-0.dll'),
 (1835213, 11178, 21184, 1, 'b', u'api-ms-win-core-localization-l1-2-0.dll'),
 (1846391, 10461, 19136, 1, 'b', u'api-ms-win-core-memory-l1-1-0.dll'),
 (1856852, 10395, 18624, 1, 'b', u'api-ms-win-core-namedpipe-l1-1-0.dll'),
 (1867247,
  10555,
  19648,
  1,
  'b',
  u'api-ms-win-core-processenvironment-l1-1-0.dll'),
 (1877802, 11078, 20672, 1, 'b', u'api-ms-win-core-processthreads-l1-1-0.dll'),
 (1888880, 10498, 19136, 1, 'b', u'api-ms-win-core-processthreads-l1-1-1.dll'),
 (1899378, 10215, 18112, 1, 'b', u'api-ms-win-core-profile-l1-1-0.dll'),
 (1909593, 10486, 19136, 1, 'b', u'api-ms-win-core-rtlsupport-l1-1-0.dll'),
 (1920079, 10347, 18624, 1, 'b', u'api-ms-win-core-string-l1-1-0.dll'),
 (1930426, 10870, 20672, 1, 'b', u'api-ms-win-core-synch-l1-1-0.dll'),
 (1941296, 10524, 19136, 1, 'b', u'api-ms-win-core-synch-l1-2-0.dll'),
 (1951820, 10598, 19648, 1, 'b', u'api-ms-win-core-sysinfo-l1-1-0.dll'),
 (1962418, 10376, 18624, 1, 'b', u'api-ms-win-core-timezone-l1-1-0.dll'),
 (1972794, 10274, 18624, 1, 'b', u'api-ms-win-core-util-l1-1-0.dll'),
 (1983068, 10607, 19648, 1, 'b', u'api-ms-win-crt-conio-l1-1-0.dll'),
 (1993675, 11729, 22720, 1, 'b', u'api-ms-win-crt-convert-l1-1-0.dll'),
 (2005404, 10429, 19136, 1, 'b', u'api-ms-win-crt-environment-l1-1-0.dll'),
 (2015833, 11063, 20672, 1, 'b', u'api-ms-win-crt-filesystem-l1-1-0.dll'),
 (2026896, 10584, 19648, 1, 'b', u'api-ms-win-crt-heap-l1-1-0.dll'),
 (2037480, 10540, 19136, 1, 'b', u'api-ms-win-crt-locale-l1-1-0.dll'),
 (2048020, 13628, 27840, 1, 'b', u'api-ms-win-crt-math-l1-1-0.dll'),
 (2061648, 10654, 19648, 1, 'b', u'api-ms-win-crt-process-l1-1-0.dll'),
 (2072302, 11901, 23232, 1, 'b', u'api-ms-win-crt-runtime-l1-1-0.dll'),
 (2084203, 12357, 24768, 1, 'b', u'api-ms-win-crt-stdio-l1-1-0.dll'),
 (2096560, 12530, 24768, 1, 'b', u'api-ms-win-crt-string-l1-1-0.dll'),
 (2109090, 11174, 21184, 1, 'b', u'api-ms-win-crt-time-l1-1-0.dll'),
 (2120264, 10601, 19136, 1, 'b', u'api-ms-win-crt-utility-l1-1-0.dll'),
 (2130865, 485, 1035, 1, 'b', u'bob_test_1.exe.manifest'),
 (2131350, 74629, 189952, 1, 'b', u'pyexpat.pyd'),
 (2205979, 1637554, 3938304, 1, 'b', u'python35.dll'),
 (3843533, 9127, 19968, 1, 'b', u'select.pyd'),
 (3852660, 446584, 982720, 1, 'b', u'ucrtbase.dll'),
 (4299244, 341035, 865792, 1, 'b', u'unicodedata.pyd'),
 (4640279,
  0,
  0,
  0,
  'o',
  u'pyi-windows-manifest-filename bob_test_1.exe.manifest'),
 (4640279, 197523, 761033, 1, 'x', u'base_library.zip'),
 (4837802, 1198430, 1198430, 0, 'z', u'out00-PYZ.pyz')]
?

Here is the simple Python script that I used to test...

# -*- coding: utf-8 -*-

import sys
from arabic_reshaper import ArabicReshaper

config1={
    'delete_harakat':False,
    'support_ligatures':True,
    'RIAL SIGN':True,
}

reshaper=ArabicReshaper(configuration=config1)
text=u"عربى"
reshaped_text=reshaper.reshape(text)

print(sys.stdout.encoding)
print(reshaped_text.encode('utf-8'))
mpcabd commented 7 years ago

Hi Bob, I think there is a problem in packaging the module, maybe it needs specific changes to be compatible with PyInstaller, I'll take a look and update the ticket

BobAchgill commented 7 years ago

Thank you! Bob


From: Abdullah Diab notifications@github.com Sent: Saturday, June 10, 2017 7:20:09 PM To: mpcabd/python-arabic-reshaper Cc: BobAchgill; Author Subject: Re: [mpcabd/python-arabic-reshaper] PyInstaller and Python-arabic-reshaper (Python 2.7) (#12)

Hi Bob, I think there is a problem in packaging the module, maybe it needs specific changes to be compatible with PyInstaller, I'll take a look and update the ticket

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpcabd/python-arabic-reshaper/issues/12#issuecomment-307597838, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYPwlM6UtzNMwfzWjU89MC7EPWgbvbM1ks5sCzK5gaJpZM4NhGfp.

mpcabd commented 7 years ago

Hi @BobAchgill,

The problem is that PyInstaller is not packaging the data files of the module when it's creating the PYZ, for some very weird reason, I couldn't really find what's going on on their end, but I managed to make it work by editing the spec file like this:

import pkg_resources
...
a = Analysis(
        ...
        datas=[
            ...,
            (
                pkg_resources.resource_filename('arabic_reshaper', 'default-config.ini'),
                'arabic_reshaper'
            ),
            ...
        ],
        ...
    )
...

This will make PyInstaller package the configuration file for this module along, it might be worth checking with PyInstaller team on what's going on, and how to solve this, because I saw that in their docs they have something similar for matplotlib data for example.

I couldn't find anything that I can do to my package to make PyInstaller pick that file up, so I'm closing the issue as well, hope this helps you, please let me know if you hear from them.

hsielecpart commented 4 years ago

Hi @BobAchgill,

The problem is that PyInstaller is not packaging the data files of the module when it's creating the PYZ, for some very weird reason, I couldn't really find what's going on on their end, but I managed to make it work by editing the spec file like this:

import pkg_resources
...
a = Analysis(
        ...
        datas=[
            ...,
            (
                pkg_resources.resource_filename('arabic_reshaper', 'default-config.ini'),
                'arabic_reshaper'
            ),
            ...
        ],
        ...
    )
...

This will make PyInstaller package the configuration file for this module along, it might be worth checking with PyInstaller team on what's going on, and how to solve this, because I saw that in their docs they have something similar for matplotlib data for example.

I couldn't find anything that I can do to my package to make PyInstaller pick that file up, so I'm closing the issue as well, hope this helps you, please let me know if you hear from them.

I did the same but it did not work for me. Any suggestion. Thanks

ravarage commented 4 years ago

@hsielecpart just copy and paste Arabic reshaper folder next to your code or generated executable file, that will resolve the issue

hsielecpart commented 4 years ago

@hsielecpart just copy and paste Arabic reshaper folder next to your code or generated executable file, that will resolve the issue

I did but still not working. Seems like pyinstaller is not finding the config file. This is the error i got. I know i have to edit or make pyinstaller know current directory(because i put the config file in the same directory) Capture

ravarage commented 4 years ago

@hsielecpart you just did opposite of what I told you, remove it from pip and python or anaconda folder, and put Arabic reshaper in the folder next to the file you are coding, and when you make an exe try to copy Arabic reshaper next to created exe

hsielecpart commented 4 years ago

@hsielecpart you just did opposite of what I told you, remove it from pip and python or anaconda folder, and put Arabic reshaper in the folder next to the file you are coding, and when you make an exe try to copy Arabic reshaper next to created exe

Thanks for your help. This is what i did after putting arabic_reshaper in my code directory I edited the arabic_reshaper and it's init file .

1-In arabic_reshaper added this line configuration_files=['your code path\arabic_reshaper\default-config.ini']

put this line after these lines to rewrite configuration_files

    configuration_files = [
        resource_filename(application_path, 'default-config.ini')
    ]

2-And in init.py in arabic_reshaper folder edited this line:

exec(open(os.path.join(os.path.dirname('your code path\arabic_reshaper\init.p'), 'version.py')).read())

It will automatically consider your config file in arabic_reshaper folder that you put inside your code