Repository navigation
Closed
Labels
Description
Description of the issue
unittest is mysteriously triggered during building, though it does not affect the (successful) building process.
This behavior is quite weird since neither unittest nor laonlp is actually imported or used in the minimal script. To reproduce this issue, besides openpyxl, LaoNLP should also be installed (via pip), since the triggered tests belong to LaoNLP.
Context information (for bug reports)
-
Output of
pyinstaller --version:6.0.0 -
Version of Python: 3.10.13
-
Platform: Windows 11 x64
-
How you installed Python: python.org/downloads
-
Did you also try this on another platform? Does it work there?
-
try the latest development version, using the following command:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip- follow all the instructions in our "If Things Go Wrong" Guide
(https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong) and
Make sure everything is packaged correctly
- start with clean installation
- use the latest development version
- Run your frozen program from a command window (shell) — instead of double-clicking on it
- Package your program in --onedir mode
- Package without UPX, say: use the option
--noupxor setupx=Falsein your .spec-file - Repackage you application in verbose/debug mode. For this, pass the option
--debugtopyi-makespecorpyinstalleror useEXE(..., debug=1, ...)in your .spec file.
A minimal example program which shows the error
import openpyxl
Stacktrace / full error message
F:\>pyinstaller --clean -y test.py
295 INFO: PyInstaller: 6.0.0
295 INFO: Python: 3.10.13
302 INFO: Platform: Windows-10-10.0.22621-SP0
303 INFO: wrote F:\test.spec
304 INFO: Removing temporary files and cleaning cache in C:\Users\BLKSerene\AppData\Local\pyinstaller
310 INFO: Extending PYTHONPATH with paths
['F:\\']
556 INFO: checking Analysis
556 INFO: Building Analysis because Analysis-00.toc is non existent
556 INFO: Initializing module dependency graph...
558 INFO: Caching module graph hooks...
571 INFO: Analyzing base_library.zip ...
1440 INFO: Loading module hook 'hook-heapq.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
1510 INFO: Loading module hook 'hook-encodings.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
2778 INFO: Loading module hook 'hook-pickle.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
3812 INFO: Caching module dependency graph...
3917 INFO: Running Analysis Analysis-00.toc
3918 INFO: Looking for Python shared library...
3922 INFO: Using Python shared library: D:\Python\python310.dll
3923 INFO: Analyzing F:\test.py
3924 INFO: Loading module hook 'hook-openpyxl.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
4023 INFO: Loading module hook 'hook-numpy.py' from 'D:\\Python\\Lib\\site-packages\\numpy\\_pyinstaller'...
4481 INFO: Loading module hook 'hook-difflib.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
4627 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
4785 INFO: Loading module hook 'hook-xml.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
5251 INFO: Loading module hook 'hook-platform.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
5284 INFO: Loading module hook 'hook-sysconfig.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
6614 INFO: Loading module hook 'hook-lxml.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
7070 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
7325 INFO: Loading module hook 'hook-PIL.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
7395 INFO: Loading module hook 'hook-PIL.Image.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
8004 INFO: Loading module hook 'hook-packaging.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
8046 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
8445 INFO: Processing module hooks...
8445 INFO: Loading module hook 'hook-lxml.etree.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8718 INFO: Loading module hook 'hook-charset_normalizer.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8858 INFO: Loading module hook 'hook-lxml.isoschematron.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8951 INFO: Loading module hook 'hook-pkg_resources.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
10068 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks'...
10482 INFO: Loading module hook 'hook-platformdirs.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
10622 INFO: Loading module hook 'hook-lxml.objectify.py' from 'D:\\Python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
10647 INFO: Looking for ctypes DLLs
10660 INFO: Analyzing run-time hooks ...
10665 INFO: Including run-time hook 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
10667 INFO: Including run-time hook 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
10673 INFO: Including run-time hook 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
10675 INFO: Including run-time hook 'D:\\Python\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
10691 INFO: Looking for dynamic libraries
D:\Python\lib\site-packages\PyInstaller\building\build_main.py:194: UserWarning: The numpy.array_api submodule is still experimental. See NEP 47.
__import__(package)
..........E
======================================================================
ERROR: tests.test_word_vector (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_word_vector
Traceback (most recent call last):
File "D:\Python\lib\site-packages\laonlp\word_vector\word2vec.py", line 20, in <module>
import gensim
ModuleNotFoundError: No module named 'gensim'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python\lib\unittest\loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "D:\Python\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
File "D:\Python\lib\site-packages\tests\test_word_vector.py", line 4, in <module>
from laonlp.word_vector import Word2Vec
File "D:\Python\lib\site-packages\laonlp\word_vector\__init__.py", line 17, in <module>
from laonlp.word_vector.word2vec import Word2Vec
File "D:\Python\lib\site-packages\laonlp\word_vector\word2vec.py", line 22, in <module>
raise ModuleNotFoundError('Word vector functionalities require gensim which is not currently installed. Please try installing the package via "pip install gensim".')
ModuleNotFoundError: Word vector functionalities require gensim which is not currently installed. Please try installing the package via "pip install gensim".
----------------------------------------------------------------------
Ran 11 tests in 0.379s
FAILED (errors=1)
17033 INFO: Extra DLL search directories (AddDllDirectory): ['D:\\Python\\lib\\site-packages\\numpy.libs']
17033 INFO: Extra DLL search directories (PATH): []
17451 INFO: Warnings written to F:\build\test\warn-test.txt
17544 INFO: Graph cross-reference written to F:\build\test\xref-test.html
17574 INFO: checking PYZ
17574 INFO: Building PYZ because PYZ-00.toc is non existent
17574 INFO: Building PYZ (ZlibArchive) F:\build\test\PYZ-00.pyz
18387 INFO: Building PYZ (ZlibArchive) F:\build\test\PYZ-00.pyz completed successfully.
18404 INFO: checking PKG
18405 INFO: Building PKG because PKG-00.toc is non existent
18405 INFO: Building PKG (CArchive) test.pkg
18421 INFO: Building PKG (CArchive) test.pkg completed successfully.
18423 INFO: Bootloader D:\Python\lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\run.exe
18423 INFO: checking EXE
18424 INFO: Building EXE because EXE-00.toc is non existent
18424 INFO: Building EXE from EXE-00.toc
18424 INFO: Copying bootloader EXE to F:\build\test\test.exe
18484 INFO: Copying icon to EXE
18542 INFO: Copying 0 resources to EXE
18542 INFO: Embedding manifest in EXE
18599 INFO: Appending PKG archive to EXE
18606 INFO: Fixing EXE headers
18980 INFO: Building EXE from EXE-00.toc completed successfully.
18981 INFO: checking COLLECT
18981 INFO: Building COLLECT because COLLECT-00.toc is non existent
18982 INFO: Removing dir F:\dist\test
18998 INFO: Building COLLECT COLLECT-00.toc
19224 INFO: Building COLLECT COLLECT-00.toc completed successfully.
Activity
bwoodsend commentedon Oct 15, 2023
Can't reproduce this in a clean environment with just PyInstaller, LaoNLP and openpyxl installed but I do notice that LaoNLP have accidentally packaged their test suite.
That still shouldn't have affected PyInstaller though...
BLKSerene commentedon Oct 15, 2023
I set up a clean environment with only the latest version of
PyInstaller,openpyxl, andLaoNLPinstalled via pip (tzdatais also required on Windows), and could confirm that this issue happens.PyInstaller: 6.1.0
OS: Windows 11 22H2 x64
Python: 3.10.13
pip list:test.py:
pyinstaller --clean -y test.py:rokm commentedon Oct 15, 2023
Looks like this import confuses modulegraph into collection of the
testspackage, so we import it prior to binary dependency scan. And the import runs the unittests.Seems that the bug can be triggered by either
from ..tests import KEEP_VBAorfrom .tests import KEEP_VBA, so this is likely a context issue (i.e., modulegraph forgets it should not be looking at global import names).As a quick work-around, you can use
--exclude tests- it is very likely that this package is not imported anywhere (so the question is why it is installed in the first place...), as that would also trigger the unit tests.rokm commentedon Oct 15, 2023
It's always nice when suspicious code blocks are already marked as such by our predecessors...
pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py
Lines 1514 to 1525 in 3ff53a8
Guess it's time we add that
if level < 1...