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

Pyinstaller error (ModuleNotFoundError: No module named 'hunspell.platform') #30

Open
balika03 opened this issue Feb 20, 2021 · 2 comments

Comments

@balika03
Copy link

balika03 commented Feb 20, 2021

Hi

My windows is: Windows 10 Pro (1909)
Python version is: 3.9.2

I installed the cyhunspell (pip install cyhunspell), after that i created a simple test.py script file with this contain (which is in the example):

from hunspell import Hunspell

h = Hunspell()
print(h.spell('correct')) # True
print(h.spell('incorect')) # False

It is worked:

E:\Novel\py\t>python test.py
True
False

But after that when i tried to create a standalone app with the pyinstaller (E:\Novel\py\t>pyinstaller test.py) and run the exe file from the dist folder (E:\Novel\py\t\dist\test>test.exe) i got this error:

Traceback (most recent call last):
  File "\\VBoxSvr\DEV\Novel\py\t\test.py", line 1, in <module>
    from hunspell import Hunspell
  File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
  File "hunspell\__init__.py", line 4, in <module>
  File "hunspell/hunspell.pyx", line 3, in init hunspell.hunspell
ModuleNotFoundError: No module named 'hunspell.platform'
[2992] Failed to execute script test

What did i do wrong? I tested the pyinstaller with the PyQt or other modules they are work well, just this module (cyhunspell) give me error.

The details when i use the pyinstaller these:

E:\Novel\py\t>pyinstaller test.py
68 INFO: PyInstaller: 4.2
69 INFO: Python: 3.9.2
69 INFO: Platform: Windows-10-10.0.18362-SP0
72 INFO: wrote E:\Novel\py\t\test.spec
75 INFO: UPX is not available.
81 INFO: Extending PYTHONPATH with paths
['E:\\Novel\\py\\t', 'E:\\Novel\\py\\t']
89 INFO: checking Analysis
89 INFO: Building Analysis because Analysis-00.toc is non existent
89 INFO: Initializing module dependency graph...
95 INFO: Caching module graph hooks...
106 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
112 INFO: Analyzing base_library.zip ...
2924 INFO: Processing pre-find module path hook distutils from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
2926 INFO: distutils: retargeting to non-venv dir 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib'
5455 INFO: Caching module dependency graph...
5653 INFO: running Analysis Analysis-00.toc
5655 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\studio\appdata\local\programs\python\python39\python.exe
5726 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of c:\users\studio\appdata\local\programs\python\python39\python39.dll
5779 INFO: Analyzing E:\Novel\py\t\test.py
5799 INFO: Processing module hooks...
5801 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5801 INFO: Excluding import of doctest from module difflib
5803 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5804 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5804 INFO: Excluding import of lib2to3.refactor from module distutils.util
5806 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5939 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5944 INFO: Excluding import of doctest from module heapq
5944 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
5998 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6000 INFO: Excluding import of test from module multiprocessing.util
6000 INFO: Excluding import of test.support from module multiprocessing.util
6000 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6003 INFO: Excluding import of argparse from module pickle
6003 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6003 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6004 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6053 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
6265 INFO: checking Tree
6265 INFO: Building Tree because Tree-00.toc is non existent
6265 INFO: Building Tree Tree-00.toc
6344 INFO: checking Tree
6344 INFO: Building Tree because Tree-01.toc is non existent
6345 INFO: Building Tree Tree-01.toc
6473 INFO: checking Tree
6473 INFO: Building Tree because Tree-02.toc is non existent
6474 INFO: Building Tree Tree-02.toc
6501 INFO: Looking for ctypes DLLs
6533 INFO: Analyzing run-time hooks ...
6536 INFO: Including run-time hook 'c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
6543 INFO: Looking for dynamic libraries
6959 INFO: Looking for eggs
6959 INFO: Using Python library c:\users\studio\appdata\local\programs\python\python39\python39.dll
6962 INFO: Found binding redirects:
[]
6965 INFO: Warnings written to E:\Novel\py\t\build\test\warn-test.txt
7032 INFO: Graph cross-reference written to E:\Novel\py\t\build\test\xref-test.html
7046 INFO: checking PYZ
7047 INFO: Building PYZ because PYZ-00.toc is non existent
7047 INFO: Building PYZ (ZlibArchive) E:\Novel\py\t\build\test\PYZ-00.pyz
7707 INFO: Building PYZ (ZlibArchive) E:\Novel\py\t\build\test\PYZ-00.pyz completed successfully.
7724 INFO: checking PKG
7724 INFO: Building PKG because PKG-00.toc is non existent
7724 INFO: Building PKG (CArchive) PKG-00.pkg
7807 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
7810 INFO: Bootloader c:\users\studio\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
7810 INFO: checking EXE
7810 INFO: Building EXE because EXE-00.toc is non existent
7812 INFO: Building EXE from EXE-00.toc
7821 INFO: Copying icons from ['c:\\users\\studio\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
7837 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
7838 INFO: Writing RT_ICON 1 resource with 3752 bytes
7839 INFO: Writing RT_ICON 2 resource with 2216 bytes
7839 INFO: Writing RT_ICON 3 resource with 1384 bytes
7839 INFO: Writing RT_ICON 4 resource with 37019 bytes
7841 INFO: Writing RT_ICON 5 resource with 9640 bytes
7841 INFO: Writing RT_ICON 6 resource with 4264 bytes
7841 INFO: Writing RT_ICON 7 resource with 1128 bytes
7867 INFO: Appending archive to EXE E:\Novel\py\t\build\test\test.exe
7920 INFO: Building EXE from EXE-00.toc completed successfully.
7923 INFO: checking COLLECT
7924 INFO: Building COLLECT because COLLECT-00.toc is non existent
7926 INFO: Building COLLECT COLLECT-00.toc
8484 INFO: Building COLLECT COLLECT-00.toc completed successfully.

Thank you your answer in advance!
Regards
B. Birtalan

@balika03
Copy link
Author

balika03 commented Feb 21, 2021

Hi,
I copied this files and folders (which are below) into the dist folder:

cacheman (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\lib\ site-packages)
future (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\lib\ site-packages)
past (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\lib\ site-packages)
psutil (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\lib\ site-packages)
imp.py (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\ lib)
six.py (from the c:\users[YOUR_USER_NAME]\appdata\local\programs\python\python39\lib\ site-packages)
hunspell\platform.py (from https://github.com/MSeal/cython_hunspell/tree/master/hunspell)
hunspell\dictionaries (from https://github.com/MSeal/cython_hunspell/tree/master/hunspell)

It is all 8-9 mb and it works, i tested on the other windows 10 (on other different pc) where the python never was installed and it works well.

I attached the zip files which includes those files which need.
need.zip

And it works on ubuntu 20.04 as well just the "putils" need to replace and overwrite from the "/usr/local/lib/python3.8" folder into the dist. I dont know why but maybe cause the os type is different (and i use 3.9 py on windows and on ubuntu run 3.8).
Otherwise I get this error:

root@balazs-VirtualBox:/mnt/dev/Novel/py/t/dist/test# ./test
Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
  File "hunspell/__init__.py", line 4, in <module>
  File "hunspell/hunspell.pyx", line 4, in init hunspell.hunspell
  File "/mnt/dev/Novel/py/t/dist/test/cacheman/cachewrap.py", line 4, in <module>
    from .registers import *
  File "/mnt/dev/Novel/py/t/dist/test/cacheman/registers.py", line 7, in <module>
    import psutil
  File "/mnt/dev/Novel/py/t/dist/test/psutil/__init__.py", line 99, in <module>
    from . import _pslinux as _psplatform
  File "/mnt/dev/Novel/py/t/dist/test/psutil/_pslinux.py", line 26, in <module>
    from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) (/mnt/dev/Novel/py/t/dist/test/psutil/__init__.py)
[5371] Failed to execute script test

But if u copy from the usr folder the psutil it works on ubuntu as well.

I know it is not the best solution, but i dont know how i would be able to sort this... best way..

Regards
B. Birtalan

@eaciv
Copy link

eaciv commented Feb 1, 2022

Following what was done here (https://github.com/mobiusklein/cython_pyinstaller_example), I was able to add a file called 'hook-hunspell.py' to my project, which contained the following:
hiddenimports = [
"hunspell.platform",
"cacheman.cachewrap",
"cacheman.cacher",
"cacheman.autosync"
]
I then added the directory where 'hook-hunspell.py' was located to the 'hookspath' property in the .spec file. As the above example mentions, you can also use the command line switch --aditional-hooks-dir. This packaged up hunspell very nicely.

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