Include dependencies in pyinstaller

0

I am creating an application in python and I need to compile it in a windows executable, I am using pyinstaller for that by:

C:\usuario>pyinstaller script.py

This generates a folder with the dependencies and the executable.

The problem is that script.py imports utilities from other own scripts, for example:

import script2
import script3

def main():
    #haciendo cosas con script2 y script3

trying to execute the file marks me an error because the scripts were not included in the list of dependencies, I would like to know how I can add these scripts in the dependencies.

Thank you in advance.

    
asked by Brayan Zavala 10.01.2018 в 23:58
source

2 answers

0

Finally it worked !!!

Thanks to the link that you gave me eyllanesc in your comment I could solve the problem.

pyinstaller can search for external dependencies, the only thing necessary is to generate a file .spec (specification file) where you specify where to look for such dependencies.

APPEARANCE OF A .SPEC FILE

a = Analysis(['script.py'],
             pathex=['C:\carpetaDelScript'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

This tells us to create a .exe file from the script.py file and that this file is inside the C:\carpetaDelScript folder defined within the variable pathex

ADDING EXTERNAL DEPENDENTS

to generate a file .spec we have to execute the command:

pyi-makespec options name.py

and to add a dependencies route we simply add the option:

--paths=[ruta de dependencias]

so the complete command would be:

pyi-makespec --paths=C:\carpetaDependencias script.py

what would generate a file .spec similar to:

 a = Analysis(['script.py'],
                 pathex=['C:\carpetaDelScript', 'C:\carpetaDependencias'],
                 binaries=[],
                 datas=[],
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)

you can add as many folders as you need

GENERATING THE .EXE

in the previous process we generated a .spec with the same name as our script, to generate the .exe we only execute the following command:

pyinstaller script.spec

this will generate a folder called dist within it will be our executable.

    
answered by 12.01.2018 / 01:37
source
0

When importing the extension .py

is not placed

It would stay:

import script2
import script3

def main():
    # haciendo cosas con script2 y script3
    
answered by 11.01.2018 в 00:15