navis-org / skeletor

Extraction of 3D skeletons from meshes.
https://navis-org.github.io/skeletor/
GNU General Public License v3.0
205 stars 25 forks source link

Using pyinstaller with navis and skeletor #22

Closed venugovh closed 2 years ago

venugovh commented 2 years ago

Hi @schlegelp !

I am building an application that requires the conversion of the skeleton to a networkxobject. For that, I am using the navismodule as per #19.

Now when I use pyinstaller, I get the error: FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\...\\AppData\\Local\\Temp\\_MEI46802\\navis\\data\\gml'

I am using python 3.7 on Windows 10. I don't know if this is a pyinstaller issue, but any input would be really helpful.

I generated the spec file and added the binaries, hiddenimportsand hookspath:

# -*- mode: python ; coding: utf-8 -*-

from PyInstaller.utils.hooks import collect_dynamic_libs
block_cipher = None

a = Analysis(['main_script_name.py'],
             pathex=['C:\\Users\\<location>'],
             binaries=collect_dynamic_libs("rtree"),
             datas=[],
             hiddenimports=['navis','vtkmodules',
                            'vtkmodules.all',
                            'vtkmodules.qt.QVTKRenderWindowInteractor',
                            'vtkmodules.util',
                            'vtkmodules.util.numpy_support',
                            'vtkmodules.numpy_interface.dataset_adapter',],
             hookspath=['hooks'],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,  
          [],
          name='main_script_name',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None )

The hooks file contains:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('trimesh')

I tried adding an additional line to the hooks file to append navis data file; but it still caused the FileNotFoundError # datas += collect_data_files('navis')

Could you please help me out here? Thanks a lot!

venugovh commented 2 years ago

I don't know if this helps, but I am using pyinstaller --onefile main_script_name.py call for generating the spec file and once I edit the spec file, I am building the .exe again using the --onefile option.

schlegelp commented 2 years ago

I have no experience with PyInstaller whatsoever but from the message it looks like it can't find the example data bundled with navis. I have no clue how you would properly configure this but there are a bunch of different .swc, .gml and .obj and .csv files.

That said: using navis for just this one purpose is massive overkill. I just added a Skeleton.get_graph method with 7f88a41ebbbef1f40e0e63a93f6e9e62039c05b2. Try it out but this should just do what you need:

>>> s = sk.skeletonize.by_wavefront(sk.example_mesh())
>>> s.get_graph()
<networkx.classes.digraph.DiGraph at 0x10db88eb0>
venugovh commented 2 years ago

Oh! That is really helpful! I will try this out. Thank you! I will close this issue once I am able to generate a working exe. :)