create exe with pyinstaller including subfolders

0

I have a project made in Python 3.4.

I want to make the executable including the sub-folders that the project has, but when executing:

pyinstaller --noconsole main.py 

do not add these subfolders

    
asked by NestorIp 03.04.2017 в 09:40
source

2 answers

0

Already this, I have already achieved it.

# -*- mode: python -*-

block_cipher = None
added_files=[('./data/*.*','data'),('./ui/*.*','ui')]

a = Analysis(['main_gia.py'],
             pathex=['C:\Users\tasl\Documents\bitbucket\gia_python'],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
        a.scripts,
        exclude_binaries=True,
        name='main_gia',
        debug=False,
        strip=False,
        upx=True,
        console=False,
        icon='./data/icon_gia.ico')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='main_gia',
               icon='./data/icon_gia.ico')

With COLLECT.

    
answered by 05.04.2017 / 11:49
source
0

By command line you can not. What you have to do is create a "specification" file of the freezing process, eg. main.spec. In fact, you may not even have to create it since the pyinstaller creates one by default with which it performs the process (be careful if you modify it because as you execute it, you will always create it destroying any change you make).

In order to run the process from the specification file, it is necessary to pass as a parameter to said file: pyinstaller --noconsole main.spec . In this file or rather python script, you have much more control over the process, and you can set which folders and / or files to add. You have to initialize an Analysis class with some of the options you need, for example:

a = Analysis(...
 datas= [ ('/mygame/sfx/*.mp3', 'sfx' ) ],
 ...
 )

What is being done is to include all the * .mp3 files of a specific folder and in the final runtime they will go to an "sfx" folder. For more information, I recommend consulting here .

    
answered by 03.04.2017 в 16:51