pattern icon indicating copy to clipboard operation
pattern copied to clipboard

pyinstaller FileNotFoundError: [Errno 2] No such file or directory: '<dir_path>/pattern/text/en/en-model.slp'

Open ritdubal3011 opened this issue 6 years ago • 1 comments

Hi,

I'm using python 3.5.2 pyinstaller 3.4 pattern == 3.6 Package installed successfully.

and imported as import pattern.text.en as p

When i create executable with pyinstaller this is throwing me runtime error.

File "importlib/__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "SWAMi_engine/urls.py", line 18, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "engine/urls.py", line 17, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "engine/views.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "engine/util.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "models.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "common_util.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "sap/train.py", line 21, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "sap/util.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/usr/local/lib/python3.5/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "pattern/text/en/__init__.py", line 140, in <module>
  File "pattern/text/__init__.py", line 1083, in __init__
  File "pattern/text/__init__.py", line 673, in __init__
  File "pattern/vector/__init__.py", line 2390, in load
  File "gzip.py", line 163, in __init__
FileNotFoundError: [Errno 2] No such file or directory: '<dir_path>/pattern/text/en/en-model.slp'

I have also tried with pip3 as well as python3 setup.py install. No luck on any of this.

ritdubal3011 avatar Jul 29 '19 06:07 ritdubal3011

The pattern library uses sys.path manipulations which sometimes don't work smoothly with PyInstaller (https://pyinstaller.readthedocs.io/en/stable/operating-mode.html)

I came up with a temporary fix which works for me smoothly. There might be a better way to solve it though:

  1. Instead of importing "pattern.en", import "pattern.text.en" as this is actually how it appears
  2. The executable was unable to find "en-model.slp" file. In the '<dir_path>/pattern/text/en/init.py', en-model.slp is defined as model = os.path.join(MODULE, "en-model.slp")
  3. At the top of the init.py where MODULE variable is defined, I temporality changed variable to empty string so that the executable finds the .slp file in the current directory (like this, MODULE = "").
  4. After the executable is created, I copied the "en-model.slp" file to the same dist directory where my executable is created. This way my executable started working.
  5. Reverted back all the changes in init.py

gupta-mrinal avatar Nov 18 '20 06:11 gupta-mrinal