HumanSignal / labelImg

LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.
https://youtu.be/p0nR2YsCY_U
MIT License
22.51k stars 6.27k forks source link

Error when trying to build binaries for ubuntu when following the readme.md #791

Closed ArnoBen closed 3 years ago

ArnoBen commented 3 years ago

Greetings,

I have made a few minor changes to labelImg and I want to build a standalone application for Ubuntu.

I followed the instructions in build-tools/readme but it fails when running sh build-ubuntu-binary.sh. By the way I don't understand why we'd need to run a docker container on the side to build the binary (this is performed by run-in-container.sh).

Here is the error that I get when running sh build-ubuntu-binary.sh :

(xxii-labelimg) arno@Arno-Ubuntu:~/Workspace/LabellingTools/xxii-labelimg/build-tools$ sh build-ubuntu-binary.sh 
HEAD est maintenant sur e98b70e7 Finished release 3.2.
83 INFO: PyInstaller: 3.2
84 INFO: Python: 3.6.14
84 INFO: Platform: Linux-5.8.0-59-generic-x86_64-with-Ubuntu-20.04-focal
84 INFO: wrote /home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/labelImg.spec
86 INFO: UPX is not available.
87 INFO: Extending PYTHONPATH with paths
['/home/arno/Workspace/LabellingTools',
 '/home/arno/Workspace/LabellingTools/xxii-labelimg/libs',
 '/home/arno/Workspace/LabellingTools/xxii-labelimg',
 '/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools']
87 INFO: checking Analysis
87 INFO: Building Analysis because out00-Analysis.toc is non existent
87 INFO: Initializing module dependency graph...
88 INFO: Initializing module graph hooks...
89 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "pyinstaller/pyinstaller.py", line 15, in <module>
    run()
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/building/build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/building/build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/building/build_main.py", line 212, in __init__
    self.__postinit__()
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/building/datastruct.py", line 178, in __postinit__
    self.assemble()
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/building/build_main.py", line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/depend/analysis.py", line 560, in initialize_modgraph
    graph.import_hook(m)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 906, in import_hook
    q, tail = self._find_head_package(parent, name, level)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 990, in _find_head_package
    q = self._safe_import_module(head, qname, parent)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/depend/analysis.py", line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 1211, in _safe_import_module
    module_name, file_handle, pathname, metadata)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 1295, in _load_module
    self._scan_code(m, co, co_ast)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 1460, in _scan_code
    self._scan_bytecode_stores(co, m)
  File "/home/arno/Workspace/LabellingTools/xxii-labelimg/build-tools/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.py", line 1505, in _scan_bytecode_stores
    name = co.co_names[oparg]
IndexError: tuple index out of range
cp: impossible d'évaluer 'dist/labelImg': Aucun fichier ou dossier de ce type
updating: linux_defaultLabelError/ (stored 0%)
updating: linux_defaultLabelError/data/ (stored 0%)
updating: linux_defaultLabelError/data/tags.yaml (deflated 13%)
updating: linux_defaultLabelError/data/predefined_classes.txt (stored 0%)

I have never used pyinstaller before, I'm watching tutorials at the moment but for now I have now idea what to try in order to make this work.

Thanks in advance, any suggestion would be appreciated.

ArnoBen commented 3 years ago

I fixed this by making a build script from scratch, and I can now successfuly compile a clickable executable for Ubuntu.

I removed everything in the build-tools directory and instead put my own shell script in this directory.

Here is my script :

pyinstaller ../labelImg.py -F \
-p ../libs -p ../ \
--name "labelImg" \
--hidden-import=pyyaml \
--hidden-import=xml \
--hidden-import=xml.etree \
--hidden-import=xml.etree.ElementTree \
--hidden-import=lxml.etree \
--onefile \
--clean

This will build a single file executable inside this directory.

I execute this from a Pipenv, here is the related Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
lxml = "==4.6.3"
PyQt5 = "==5.15.4"
pyqtchart = "==5.15.4"
pyyaml = "==5.4.1"

[dev-packages]
pyinstaller = "==4.5.1"

[requires]
python_version = "3.6"

Don't forget to install the pipenv with pipenv install --dev to install pyinstaller as well.

Cheers !